結果

問題 No.1354 Sambo's Treasure
ユーザー titiatitia
提出日時 2021-09-01 23:19:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,107 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 264,932 KB
最終ジャッジ日時 2024-05-06 13:15:15
合計ジャッジ時間 8,015 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
140,928 KB
testcase_01 AC 110 ms
135,680 KB
testcase_02 AC 108 ms
136,064 KB
testcase_03 AC 106 ms
135,936 KB
testcase_04 AC 106 ms
136,192 KB
testcase_05 AC 109 ms
135,936 KB
testcase_06 AC 108 ms
136,192 KB
testcase_07 AC 107 ms
135,808 KB
testcase_08 AC 109 ms
135,936 KB
testcase_09 AC 107 ms
135,808 KB
testcase_10 AC 109 ms
135,808 KB
testcase_11 AC 105 ms
136,064 KB
testcase_12 AC 104 ms
135,552 KB
testcase_13 AC 105 ms
135,924 KB
testcase_14 AC 106 ms
135,808 KB
testcase_15 AC 107 ms
136,192 KB
testcase_16 AC 107 ms
136,272 KB
testcase_17 AC 106 ms
135,936 KB
testcase_18 AC 105 ms
136,064 KB
testcase_19 AC 107 ms
136,192 KB
testcase_20 AC 106 ms
135,680 KB
testcase_21 AC 106 ms
136,064 KB
testcase_22 AC 109 ms
135,680 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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]

    #print(LIST)

    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]
                    NDP[l+1]%=mod

            else:
                for l in range(k+1):
                    NDP[l]+=COM*DP[k][l]
                    NDP[l]%=mod

        #print(NDP)
                
        if j!=len(LIST)-1:
            for l in range(1,j):
                NDP[l]-=NDP[l+1]
        else:            
            for l in range(j):
                NDP[l]-=NDP[l+1]

        #print(NDP)

        DP[j]=NDP

    #print(DP)

    dp=DP[-1]

    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]
            NEXT[i+j]%=mod

    NOW=NEXT

#print(NOW)
print(sum(NOW[:K+1])%mod)
            

        
        
        
        
0