結果
問題 | No.1354 Sambo's Treasure |
ユーザー | titia |
提出日時 | 2021-09-01 23:32:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 392 ms / 2,000 ms |
コード長 | 2,176 bytes |
コンパイル時間 | 162 ms |
コンパイル使用メモリ | 82,424 KB |
実行使用メモリ | 141,440 KB |
最終ジャッジ日時 | 2024-11-28 20:34:11 |
合計ジャッジ時間 | 14,116 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 107 ms
135,424 KB |
testcase_01 | AC | 99 ms
135,808 KB |
testcase_02 | AC | 104 ms
135,552 KB |
testcase_03 | AC | 99 ms
135,424 KB |
testcase_04 | AC | 103 ms
135,424 KB |
testcase_05 | AC | 101 ms
136,064 KB |
testcase_06 | AC | 98 ms
135,808 KB |
testcase_07 | AC | 102 ms
135,296 KB |
testcase_08 | AC | 101 ms
135,808 KB |
testcase_09 | AC | 101 ms
135,680 KB |
testcase_10 | AC | 100 ms
135,936 KB |
testcase_11 | AC | 100 ms
135,808 KB |
testcase_12 | AC | 101 ms
135,808 KB |
testcase_13 | AC | 101 ms
135,552 KB |
testcase_14 | AC | 101 ms
135,808 KB |
testcase_15 | AC | 100 ms
135,424 KB |
testcase_16 | AC | 102 ms
136,192 KB |
testcase_17 | AC | 101 ms
135,808 KB |
testcase_18 | AC | 99 ms
135,552 KB |
testcase_19 | AC | 101 ms
135,424 KB |
testcase_20 | AC | 100 ms
135,680 KB |
testcase_21 | AC | 102 ms
135,552 KB |
testcase_22 | AC | 100 ms
135,296 KB |
testcase_23 | AC | 348 ms
131,472 KB |
testcase_24 | AC | 360 ms
131,416 KB |
testcase_25 | AC | 296 ms
131,172 KB |
testcase_26 | AC | 366 ms
131,552 KB |
testcase_27 | AC | 372 ms
132,188 KB |
testcase_28 | AC | 361 ms
131,804 KB |
testcase_29 | AC | 295 ms
130,776 KB |
testcase_30 | AC | 344 ms
130,920 KB |
testcase_31 | AC | 366 ms
132,084 KB |
testcase_32 | AC | 298 ms
131,168 KB |
testcase_33 | AC | 309 ms
131,808 KB |
testcase_34 | AC | 392 ms
131,552 KB |
testcase_35 | AC | 290 ms
130,660 KB |
testcase_36 | AC | 350 ms
131,420 KB |
testcase_37 | AC | 352 ms
131,168 KB |
testcase_38 | AC | 364 ms
131,428 KB |
testcase_39 | AC | 353 ms
131,300 KB |
testcase_40 | AC | 348 ms
131,520 KB |
testcase_41 | AC | 372 ms
131,904 KB |
testcase_42 | AC | 352 ms
131,044 KB |
testcase_43 | AC | 117 ms
140,800 KB |
testcase_44 | AC | 115 ms
141,056 KB |
testcase_45 | AC | 114 ms
140,928 KB |
testcase_46 | AC | 116 ms
141,184 KB |
testcase_47 | AC | 117 ms
140,928 KB |
testcase_48 | AC | 115 ms
140,928 KB |
testcase_49 | AC | 117 ms
140,544 KB |
testcase_50 | AC | 117 ms
140,544 KB |
testcase_51 | AC | 115 ms
140,672 KB |
testcase_52 | AC | 118 ms
140,800 KB |
testcase_53 | AC | 117 ms
140,800 KB |
testcase_54 | AC | 115 ms
141,184 KB |
testcase_55 | AC | 115 ms
140,544 KB |
testcase_56 | AC | 115 ms
141,440 KB |
testcase_57 | AC | 116 ms
141,184 KB |
testcase_58 | AC | 114 ms
140,672 KB |
testcase_59 | AC | 115 ms
140,672 KB |
testcase_60 | AC | 116 ms
140,928 KB |
testcase_61 | AC | 113 ms
141,184 KB |
testcase_62 | AC | 115 ms
141,440 KB |
testcase_63 | AC | 384 ms
131,552 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)