結果

問題 No.655 E869120 and Good Triangles
ユーザー vwxyzvwxyz
提出日時 2022-06-29 05:09:31
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,799 bytes
コンパイル時間 1,265 ms
コンパイル使用メモリ 77,316 KB
実行使用メモリ 359,292 KB
最終ジャッジ日時 2023-08-14 06:34:53
合計ジャッジ時間 59,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
77,804 KB
testcase_01 AC 82 ms
77,916 KB
testcase_02 AC 84 ms
77,852 KB
testcase_03 AC 82 ms
78,000 KB
testcase_04 AC 82 ms
78,008 KB
testcase_05 AC 81 ms
78,088 KB
testcase_06 AC 83 ms
78,108 KB
testcase_07 AC 81 ms
78,076 KB
testcase_08 AC 81 ms
78,188 KB
testcase_09 AC 83 ms
78,272 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 AC 1,959 ms
346,340 KB
testcase_25 AC 1,815 ms
347,740 KB
testcase_26 AC 1,798 ms
348,768 KB
testcase_27 AC 2,103 ms
348,308 KB
testcase_28 AC 1,784 ms
346,088 KB
testcase_29 AC 2,202 ms
346,812 KB
testcase_30 AC 83 ms
78,012 KB
testcase_31 AC 82 ms
78,332 KB
testcase_32 AC 84 ms
78,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0