結果
問題 | No.655 E869120 and Good Triangles |
ユーザー | vwxyz |
提出日時 | 2022-06-29 05:09:18 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,799 bytes |
コンパイル時間 | 336 ms |
コンパイル使用メモリ | 82,320 KB |
実行使用メモリ | 354,156 KB |
最終ジャッジ日時 | 2024-05-01 19:19:39 |
合計ジャッジ時間 | 23,915 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
56,340 KB |
testcase_01 | AC | 37 ms
55,008 KB |
testcase_02 | AC | 37 ms
55,552 KB |
testcase_03 | AC | 37 ms
54,592 KB |
testcase_04 | AC | 37 ms
56,152 KB |
testcase_05 | AC | 37 ms
55,040 KB |
testcase_06 | AC | 36 ms
54,304 KB |
testcase_07 | AC | 38 ms
55,248 KB |
testcase_08 | AC | 37 ms
55,964 KB |
testcase_09 | AC | 37 ms
54,632 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | AC | 2,498 ms
353,672 KB |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | AC | 2,474 ms
352,140 KB |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | AC | 2,439 ms
352,256 KB |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | AC | 2,482 ms
350,748 KB |
testcase_23 | TLE | - |
testcase_24 | AC | 1,675 ms
342,004 KB |
testcase_25 | AC | 1,543 ms
343,016 KB |
testcase_26 | AC | 1,587 ms
342,776 KB |
testcase_27 | AC | 1,852 ms
342,684 KB |
testcase_28 | AC | 1,640 ms
341,112 KB |
testcase_29 | AC | 1,954 ms
341,752 KB |
testcase_30 | AC | 39 ms
54,604 KB |
testcase_31 | AC | 39 ms
54,508 KB |
testcase_32 | AC | 37 ms
55,320 KB |
ソースコード
import sys from collections import deque readline=sys.stdin.readline N,K,P=map(int,readline().split()) inf=1<<30 A=[[inf]*(i+1) for i in range(N)] queue=deque([]) for _ in range(K): x,y=map(int,readline().split()) x-=1;y-=1 queue.append((x,y)) A[x][y]=0 while queue: x,y=queue.popleft() if 0<=y-1<=x-1<N and A[x][y]+1<A[x-1][y-1]: A[x-1][y-1]=A[x][y]+1 queue.append((x-1,y-1)) if 0<=y<=x-1<N and A[x][y]+1<A[x-1][y]: A[x-1][y]=A[x][y]+1 queue.append((x-1,y)) if 0<=y-1<=x<N and A[x][y]+1<A[x][y-1]: A[x][y-1]=A[x][y]+1 queue.append((x,y-1)) if 0<=y+1<=x<N and A[x][y]+1<A[x][y+1]: A[x][y+1]=A[x][y]+1 queue.append((x,y+1)) if 0<=y<=x+1<N and A[x][y]+1<A[x+1][y]: A[x+1][y]=A[x][y]+1 queue.append((x+1,y)) if 0<=y+1<=x+1<N and A[x][y]+1<A[x+1][y+1]: A[x+1][y+1]=A[x][y]+1 queue.append((x+1,y+1)) AL=[[A[i][j] for j in range(i+1)] for i in range(N)] AR=[[A[i][j] for j in range(i+1)] for i in range(N)] for i in range(1,N): for j in range(i): AL[i][j]+=AL[i-1][j] for i in range(1,N): for j in range(1,i+1): AR[i][j]+=AR[i-1][j-1] for i in range(N): A[i]=[0]+A[i] for j in range(1,i+2): A[i][j]+=A[i][j-1] ans=0 dp=[(0,0)] for i in range(N): prev=dp dp=[(0,0)]*(i+2) for j in range(i+1): ii,s=prev[j] while ii<N and s<P: s+=A[ii][j-i+ii+1]-A[ii][j] ii+=1 prev[j]=(ii,s) if i!=N-1: dp[j]=max(dp[j],(ii,s-(AR[ii-1][j-i+ii-1]-(AR[i-1][j-1] if i and j else 0)))) dp[j+1]=max(dp[j+1],(ii,s-(AL[ii-1][j]-(AL[i-1][j] if i and i!=j else 0)))) for j in range(i+1): if prev[j][1]>=P: ans+=N-prev[j][0]+1 print(ans)