結果

問題 No.655 E869120 and Good Triangles
ユーザー vwxyzvwxyz
提出日時 2022-06-29 05:09:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,799 bytes
コンパイル時間 482 ms
コンパイル使用メモリ 11,072 KB
実行使用メモリ 103,072 KB
最終ジャッジ日時 2023-08-14 06:33:46
合計ジャッジ時間 4,640 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
13,176 KB
testcase_01 AC 19 ms
8,888 KB
testcase_02 AC 18 ms
8,844 KB
testcase_03 AC 20 ms
8,952 KB
testcase_04 AC 19 ms
8,820 KB
testcase_05 AC 19 ms
8,788 KB
testcase_06 AC 19 ms
8,864 KB
testcase_07 AC 19 ms
8,780 KB
testcase_08 AC 19 ms
8,864 KB
testcase_09 AC 19 ms
8,760 KB
testcase_10 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

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