結果

問題 No.2826 Earthwork
ユーザー FplusFplusFFplusFplusF
提出日時 2024-07-26 17:12:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 2,206 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 13,184 KB
実行使用メモリ 477,808 KB
最終ジャッジ日時 2024-07-26 17:13:29
合計ジャッジ時間 10,060 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
11,392 KB
testcase_01 AC 328 ms
21,248 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n=int(input())
h=[list(map(int,input().split())) for i in range(n)]
s=[input() for i in range(n)]
a=[list(map(int,input().split())) for i in range(n-1)]
b=[list(map(int,input().split())) for i in range(n)]
q=int(input())
rce=[tuple(map(int,input().split())) for i in range(q)]

INF=int(4e18)

def to(i,j):
    return i*n+j

mx=[-INF]*n*n

for t in range(2):

    g=[[] for i in range(n*n+1)]

    for i in range(n-1):
        for j in range(n):
            p=h[i][j]+h[i+1][j]
            l=-p-a[i][j]*abs(p)
            r=-p+a[i][j]*abs(p)
            if (i+j)%2==t:
                g[to(i,j)].append((to(i+1,j),-l))
                g[to(i+1,j)].append((to(i,j),r))
            else:
                g[to(i,j)].append((to(i+1,j),r))
                g[to(i+1,j)].append((to(i,j),-l))
    for i in range(n):
        for j in range(n-1):
            p=h[i][j]+h[i][j+1]
            l=-p-b[i][j]*abs(p)
            r=-p+b[i][j]*abs(p)
            if (i+j)%2==t:
                g[to(i,j)].append((to(i,j+1),-l))
                g[to(i,j+1)].append((to(i,j),r))
            else:
                g[to(i,j)].append((to(i,j+1),r))
                g[to(i,j+1)].append((to(i,j),-l))
    
    for i in range(n):
        for j in range(n):
            if s[i][j]=='=' or s[i][j]=='-':
                if (i+j)%2==t:
                    g[n*n].append((to(i,j),0))
                else:
                    g[to(i,j)].append((n*n,0))
            if s[i][j]=='=' or s[i][j]=='+':
                if (i+j)%2==t:
                    g[to(i,j)].append((n*n,0))
                else:
                    g[n*n].append((to(i,j),0))

    dist=[INF]*(n*n+1)
    dist[n*n]=0
    hq=[(0,n*n)]
    heapq.heapify(hq)

    while hq:
        d,i=heapq.heappop(hq)
        if d!=dist[i]:
            continue        
        for ti,td in g[i]:
            if dist[i]+td<dist[ti]:
                dist[ti]=dist[i]+td
                heapq.heappush(hq,(dist[ti],ti))

    for i in range(n):
        for j in range(n):
            if (i+j)%2==t:
                mx[to(i,j)]=max(mx[to(i,j)],h[i][j]+dist[to(i,j)])

for r,c,e in rce:
    r-=1
    c-=1
    if e<=mx[to(r,c)]:
        print("Yes")
    else:
        print("No")
0