#2327616

Solution for 0122: Summer of Pyonkichi by peroon

Source Code Status Test Cases
    Policy: public     Reviewed: 4    
00.03 sec    7760 KB    80 lines     1537 bytes    2017-05-20 04:05
# -*- coding: utf-8 -*-

import sys
import os
import math

def jump_candidate(pos):
    x = pos[0]
    y = pos[1]

    candidate_list = []

    A = []
    A.append((-2, 0))
    A.append((-2, -1))
    A.append((-2, +1))
    A.append((+2, 0))
    A.append((+2, -1))
    A.append((+2, +1))
    A.append((0, -2))
    A.append((-1, -2))
    A.append((+1, -2))
    A.append((0, +2))
    A.append((-1, +2))
    A.append((+1, +2))

    for a in A:
        next_x = x + a[0]
        next_y = y + a[1]
        if 0 <= next_x <= 9 and 0 <= next_y <= 9:
            candidate_list.append((next_x, next_y))

    return candidate_list

def in_sprinkler_range(frog_pos, sprinkler_pos):
    fx = frog_pos[0]
    fy = frog_pos[1]
    sx = sprinkler_pos[0]
    sy = sprinkler_pos[1]

    if sx - 1 <= fx <= sx + 1 and sy - 1 <= fy <= sy + 1:
        return True
    else:
        return False


for s in sys.stdin:
    px, py = map(int, s.split())

    if px == py == 0:
        break

    n = int(input())

    lst = list(map(int, input().split()))

    # solve
    survivers = [(px, py)]
    for i in range(n):
        sprinkler = (lst[2 * i], lst[2 * i + 1])

        next_survivers = []

        for surviver in survivers:
            pos_candidates = jump_candidate(surviver)

            for jump_pos in pos_candidates:
                if in_sprinkler_range(sprinkler, jump_pos):
                    next_survivers.append(jump_pos)

        survivers = next_survivers

    if len(survivers) == 0:
        print('NA')
    else:
        print('OK')




Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 1/1 Python3 CPU: 00.03 sec Memory: 7760 KB Length: 1537 B 2017-05-20 04:05 2017-05-20 04:05
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.03 sec 7760 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags