답안 #635638

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635638 2022-08-26T14:33:41 Z karolb2011 Furniture (JOI20_furniture) Python 3
0 / 100
23 ms 3284 KB
import sys
input=sys.stdin.readline
n,m=list(map(int,input().split()))
f=[]
for i in range(n):
    f.append(list(map(int,input().split())))
i,j=0,0
h=[0 for i in range(n)]
v=[0 for i in range(m)]
while True:
    if j<m-1 and f[i][j+1]==0:
        j+=1
        h[i]=j
        f[i][j]+=2
    elif f[i+1][j]==0:
        i+=1
        h[i]=j
        f[i][j]+=10
    elif f[i][j]==2:
        f[i][j]=1
        j-=1
        h[i]=j
    else:
        f[i][j]=1
        i-=1
    if i==n-1 and j==m-1:
        break
i,j=0,0
while True:
    if i<n-1 and f[i+1][j]%2==0:
        i+=1
        v[j]=i
        f[i][j]+=4
    elif f[i][j+1]%2==0:
        j+=1
        v[j]=i
        f[i][j]+=20
    elif f[i][j]//16==0:
        f[i][j]=1
        i-=1
        v[j]=i
    else:
        f[i][j]=1
        j-=1
    if i==n-1 and j==m-1:
        break
q=int(input())
for _ in range(q):
    i,j=list(map(int,input().split()))
    i-=1
    j-=1
    if j>h[i] or i>v[j]:
        print(1)
    elif f[i][j]%8==6:
        print(0)
    elif f[i][j]%8==0:
        print(1)
    else:
        print(1)
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3008 KB Output is correct
2 Incorrect 23 ms 3284 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 3008 KB Output is correct
2 Incorrect 23 ms 3284 KB Output isn't correct
3 Halted 0 ms 0 KB -