結果

問題 No.655 E869120 and Good Triangles
ユーザー vwxyzvwxyz
提出日時 2022-06-29 05:05:38
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,866 bytes
コンパイル時間 311 ms
コンパイル使用メモリ 82,356 KB
実行使用メモリ 414,632 KB
最終ジャッジ日時 2024-11-22 01:22:31
合計ジャッジ時間 60,242 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 159 ms
96,032 KB
testcase_01 AC 139 ms
414,632 KB
testcase_02 AC 141 ms
94,776 KB
testcase_03 AC 141 ms
89,476 KB
testcase_04 AC 144 ms
89,204 KB
testcase_05 AC 139 ms
89,224 KB
testcase_06 AC 144 ms
89,276 KB
testcase_07 AC 144 ms
89,380 KB
testcase_08 AC 145 ms
89,520 KB
testcase_09 AC 142 ms
89,096 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,968 ms
344,176 KB
testcase_25 AC 1,788 ms
345,056 KB
testcase_26 AC 1,785 ms
344,332 KB
testcase_27 AC 2,077 ms
345,408 KB
testcase_28 AC 1,840 ms
343,292 KB
testcase_29 AC 2,162 ms
344,296 KB
testcase_30 AC 142 ms
89,432 KB
testcase_31 AC 141 ms
89,432 KB
testcase_32 AC 144 ms
363,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines

class Cumsum:
    def __init__(self,lst,mod=0):
        self.N=len(lst)
        self.mod=mod
        self.cumsum=[0]*(self.N+1)
        self.cumsum[0]=0
        for i in range(1,self.N+1):
            self.cumsum[i]=self.cumsum[i-1]+lst[i-1]
            if self.mod:
                self.cumsum[i]%=self.mod

    def __getitem__(self,i):
        if type(i)==int:
            if 0<=i<self.N:
                a,b=i,i+1
            elif -self.N<=i<0:
                a,b=i+self.N,i+self.N+1
            else:
                raise IndexError('list index out of range')
        else:
            a,b=i.start,i.stop
            if a==None or a<-self.N:
                a=0
            elif self.N<=a:
                a=self.N
            elif a<0:
                a+=self.N
            if b==None or self.N<=b:
                b=self.N
            elif b<-self.N:
                b=0
            elif b<0:
                b+=self.N
        s=self.cumsum[b]-self.cumsum[a]
        if self.mod:
            s%=self.mod
        return s

    def __setitem__(self,i,x):
        if -self.N<=i<0:
            i+=self.N
        elif not 0<=i<self.N:
            raise IndexError('list index out of range')
        self.cumsum[i+1]=self.cumsum[i]+x
        if self.mod:
            self.cumsum[i+1]%=self.mod

    def __str__(self):
        lst=[self.cumsum[i+1]-self.cumsum[i] for i in range(self.N)]
        if self.mod:
            for i in range(self.N):
                lst[i]%=self.mod
        return "["+", ".join(map(str,lst))+"]"

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]=Cumsum(A[i])
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:j-i+ii+1]
            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