結果
問題 | No.1354 Sambo's Treasure |
ユーザー | titia |
提出日時 | 2021-09-01 23:32:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 375 ms / 2,000 ms |
コード長 | 2,176 bytes |
コンパイル時間 | 408 ms |
コンパイル使用メモリ | 82,156 KB |
実行使用メモリ | 141,312 KB |
最終ジャッジ日時 | 2024-05-06 13:40:47 |
合計ジャッジ時間 | 14,270 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 109 ms
135,680 KB |
testcase_01 | AC | 111 ms
135,552 KB |
testcase_02 | AC | 104 ms
135,808 KB |
testcase_03 | AC | 103 ms
135,936 KB |
testcase_04 | AC | 105 ms
136,064 KB |
testcase_05 | AC | 103 ms
136,064 KB |
testcase_06 | AC | 104 ms
135,936 KB |
testcase_07 | AC | 103 ms
135,680 KB |
testcase_08 | AC | 104 ms
135,808 KB |
testcase_09 | AC | 103 ms
135,552 KB |
testcase_10 | AC | 105 ms
135,808 KB |
testcase_11 | AC | 102 ms
135,680 KB |
testcase_12 | AC | 104 ms
135,808 KB |
testcase_13 | AC | 104 ms
135,936 KB |
testcase_14 | AC | 102 ms
135,936 KB |
testcase_15 | AC | 102 ms
135,424 KB |
testcase_16 | AC | 105 ms
135,936 KB |
testcase_17 | AC | 106 ms
135,680 KB |
testcase_18 | AC | 112 ms
135,936 KB |
testcase_19 | AC | 109 ms
135,808 KB |
testcase_20 | AC | 110 ms
135,680 KB |
testcase_21 | AC | 108 ms
135,552 KB |
testcase_22 | AC | 105 ms
135,680 KB |
testcase_23 | AC | 338 ms
131,592 KB |
testcase_24 | AC | 343 ms
131,676 KB |
testcase_25 | AC | 292 ms
130,660 KB |
testcase_26 | AC | 357 ms
131,684 KB |
testcase_27 | AC | 375 ms
131,688 KB |
testcase_28 | AC | 347 ms
131,808 KB |
testcase_29 | AC | 288 ms
130,516 KB |
testcase_30 | AC | 335 ms
131,436 KB |
testcase_31 | AC | 355 ms
131,984 KB |
testcase_32 | AC | 291 ms
130,936 KB |
testcase_33 | AC | 292 ms
131,452 KB |
testcase_34 | AC | 372 ms
132,192 KB |
testcase_35 | AC | 281 ms
131,296 KB |
testcase_36 | AC | 321 ms
131,040 KB |
testcase_37 | AC | 332 ms
131,320 KB |
testcase_38 | AC | 336 ms
131,548 KB |
testcase_39 | AC | 340 ms
131,428 KB |
testcase_40 | AC | 344 ms
131,296 KB |
testcase_41 | AC | 362 ms
131,780 KB |
testcase_42 | AC | 331 ms
131,392 KB |
testcase_43 | AC | 114 ms
140,672 KB |
testcase_44 | AC | 114 ms
140,800 KB |
testcase_45 | AC | 116 ms
140,672 KB |
testcase_46 | AC | 123 ms
141,056 KB |
testcase_47 | AC | 118 ms
141,056 KB |
testcase_48 | AC | 117 ms
140,800 KB |
testcase_49 | AC | 126 ms
140,544 KB |
testcase_50 | AC | 125 ms
140,672 KB |
testcase_51 | AC | 123 ms
140,800 KB |
testcase_52 | AC | 122 ms
140,800 KB |
testcase_53 | AC | 122 ms
140,928 KB |
testcase_54 | AC | 118 ms
141,184 KB |
testcase_55 | AC | 116 ms
140,928 KB |
testcase_56 | AC | 119 ms
140,800 KB |
testcase_57 | AC | 118 ms
140,800 KB |
testcase_58 | AC | 118 ms
140,800 KB |
testcase_59 | AC | 117 ms
141,312 KB |
testcase_60 | AC | 115 ms
140,672 KB |
testcase_61 | AC | 115 ms
140,800 KB |
testcase_62 | AC | 117 ms
140,800 KB |
testcase_63 | AC | 360 ms
131,740 KB |
ソースコード
import sys input = sys.stdin.readline from operator import itemgetter N,M,L,K=map(int,input().split()) C=[tuple(map(int,input().split())) for i in range(M)] T=[tuple(map(int,input().split())) for i in range(L)] mod=998244353 C.append((N,N)) FACT=[1] for i in range(1,5*10**5+1): FACT.append(FACT[-1]*i%mod) FACT_INV=[pow(FACT[-1],mod-2,mod)] for i in range(5*10**5,0,-1): FACT_INV.append(FACT_INV[-1]*i%mod) FACT_INV.reverse() def Combi(a,b): if 0<=b<=a: return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod else: return 0 C.sort() T.sort() for i in range(1,M+1): if C[i][1]<C[i-1][1]: print(0) exit() T2=[[] for i in range(M+1)] ind=0 C.append((0,0)) for i in range(M+1): x,y=C[i] while ind<L and (T[ind][0]<x or (T[ind][0]==x and T[ind][1]<=y)): if C[i-1][1]<=T[ind][1]<=C[i][1]: T2[i].append(T[ind]) ind+=1 NOW=[1] for i in range(M+1): sx,sy=C[i-1] gx,gy=C[i] LIST=[(sx,sy)]+T2[i]+[(gx,gy)] DP=[[] for i in range(len(LIST))] DP[0]=[1] for j in range(1,len(LIST)): tx,ty=LIST[j] NDP=[0]*(j+1) for k in range(j-1,-1,-1): x,y=LIST[k] COM=Combi((tx-x)+(ty-y),(tx-x)) if j!=len(LIST)-1: for l in range(k+1): NDP[l+1]+=COM*DP[k][l]%mod NDP[l+1]%=mod else: for l in range(k+1): NDP[l]+=COM*DP[k][l]%mod NDP[l]%=mod if j!=len(LIST)-1: for l in range(1,j): NDP[l]-=NDP[l+1] NDP[l]%=mod else: for l in range(j): NDP[l]-=NDP[l+1] NDP[l]%=mod DP[j]=NDP dp=DP[-1] while dp[-1]==0: dp.pop() NEXT=[0]*(len(dp)+len(NOW)) for i in range(len(dp)): for j in range(len(NOW)): NEXT[i+j]+=dp[i]*NOW[j]%mod NEXT[i+j]%=mod NOW=NEXT while NOW[-1]==0: NOW.pop() ANS=0 for i in range(min(len(NOW),K+1)): ANS+=NOW[i] ANS%=mod print(ANS)