답안 #83470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83470 2018-11-08T08:03:36 Z charlies_moo Spirale (COCI18_spirale) PyPy
0 / 80
1000 ms 11664 KB
n, m, k = map(int, raw_input().split())
s = max(m,n)
inf = (s*2)**3+s
arr = [[inf for i in range(m+2)] for i in range(n+2)]


def print_arr():
    for i in range(1, n+1):
        for j in range(1, m+1):
            print arr[i][j],
        print



def spiral(x, y, d):
    if d == 0:
        d = 1
    else:
        d = -1
    num = 1
    arr[x][y] = num
    times = 1
    length = 1
    t = -1
    while times < n * m:
        i = 1
        while i <= length:
            num += 1
            x += t
            if x <= 0 or x >= n + 1 or y <= 0 or y >= m + 1:
                continue
            if num < arr[x][y]:
                arr[x][y] = num
            times += 1
            i += 1
        t = 0 - t
        i = 1
        while i <= length:
            num += 1
            y += t*d
            if x <= 0 or x >= n + 1 or y <= 0 or y >= m + 1:
                continue
            if num < arr[x][y]:
                arr[x][y] = num
            times += 1
            i += 1
        length += 1


for i in range(k):
    x, y, k = map(int, raw_input().split())
    spiral(x, y, k)
print_arr()
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1073 ms 11240 KB Time limit exceeded
2 Execution timed out 1075 ms 11384 KB Time limit exceeded
3 Execution timed out 1085 ms 11384 KB Time limit exceeded
4 Execution timed out 1085 ms 11384 KB Time limit exceeded
5 Execution timed out 1072 ms 11384 KB Time limit exceeded
6 Execution timed out 1080 ms 11532 KB Time limit exceeded
7 Execution timed out 1075 ms 11532 KB Time limit exceeded
8 Execution timed out 1092 ms 11532 KB Time limit exceeded
9 Execution timed out 1080 ms 11652 KB Time limit exceeded
10 Execution timed out 1080 ms 11664 KB Time limit exceeded