結果
問題 | No.1696 Nonnil |
ユーザー | chineristAC |
提出日時 | 2021-10-01 22:29:27 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 267 ms / 3,500 ms |
コード長 | 1,850 bytes |
コンパイル時間 | 230 ms |
コンパイル使用メモリ | 82,144 KB |
実行使用メモリ | 117,260 KB |
最終ジャッジ日時 | 2024-07-19 12:18:21 |
合計ジャッジ時間 | 9,049 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 55 ms
66,692 KB |
testcase_01 | AC | 59 ms
66,316 KB |
testcase_02 | AC | 56 ms
66,632 KB |
testcase_03 | AC | 207 ms
110,456 KB |
testcase_04 | AC | 54 ms
65,808 KB |
testcase_05 | AC | 54 ms
66,176 KB |
testcase_06 | AC | 57 ms
66,144 KB |
testcase_07 | AC | 57 ms
65,900 KB |
testcase_08 | AC | 191 ms
111,304 KB |
testcase_09 | AC | 100 ms
81,868 KB |
testcase_10 | AC | 108 ms
85,248 KB |
testcase_11 | AC | 98 ms
81,800 KB |
testcase_12 | AC | 102 ms
81,808 KB |
testcase_13 | AC | 98 ms
81,700 KB |
testcase_14 | AC | 242 ms
113,064 KB |
testcase_15 | AC | 121 ms
83,848 KB |
testcase_16 | AC | 256 ms
106,920 KB |
testcase_17 | AC | 218 ms
107,788 KB |
testcase_18 | AC | 167 ms
91,088 KB |
testcase_19 | AC | 56 ms
66,888 KB |
testcase_20 | AC | 56 ms
66,704 KB |
testcase_21 | AC | 184 ms
99,396 KB |
testcase_22 | AC | 193 ms
95,836 KB |
testcase_23 | AC | 189 ms
93,368 KB |
testcase_24 | AC | 184 ms
93,232 KB |
testcase_25 | AC | 235 ms
109,516 KB |
testcase_26 | AC | 214 ms
99,808 KB |
testcase_27 | AC | 241 ms
111,732 KB |
testcase_28 | AC | 207 ms
101,336 KB |
testcase_29 | AC | 205 ms
106,972 KB |
testcase_30 | AC | 165 ms
92,548 KB |
testcase_31 | AC | 225 ms
112,436 KB |
testcase_32 | AC | 231 ms
106,684 KB |
testcase_33 | AC | 221 ms
104,316 KB |
testcase_34 | AC | 191 ms
96,288 KB |
testcase_35 | AC | 210 ms
102,236 KB |
testcase_36 | AC | 254 ms
105,768 KB |
testcase_37 | AC | 267 ms
117,204 KB |
testcase_38 | AC | 251 ms
105,756 KB |
testcase_39 | AC | 257 ms
117,176 KB |
testcase_40 | AC | 266 ms
117,260 KB |
testcase_41 | AC | 150 ms
87,360 KB |
testcase_42 | AC | 198 ms
109,720 KB |
ソースコード
from math import radians import sys,random input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) def cmb(n, r, mod): if ( r<0 or r>n ): return 0 return (g1[n] * g2[r] % mod) * g2[n-r] % mod mod = 998244353 N = 2*10**5 g1 = [1]*(N+1) g2 = [1]*(N+1) inverse = [1]*(N+1) for i in range( 2, N + 1 ): g1[i]=( ( g1[i-1] * i ) % mod ) inverse[i]=( ( -inverse[mod % i] * (mod//i) ) % mod ) g2[i]=( (g2[i-1] * inverse[i]) % mod ) inverse[0]=0 N,K = mi() M = int(input()) L = [-1 for r in range(K+1)] for _ in range(M): l,r = mi() L[r] = max(L[r],l) first = [0 for r in range(K+1)] for r in range(1,K+1): tmp = -1 for l in range(r,-1,-1): tmp = max(tmp,L[l]) if tmp<=l: first[r] = l else: break else: first[r] = 0 dp = [[0 for i in range(K+1)] for r in range(K+1)] cum = [[0 for i in range(K+1)] for r in range(K+1)] dp[0][0] = 1 cum[0][0] = 1 #print(first) for r in range(1,K+1): if first[r]==0: dp[r][0] = 1 cum[r][0] = cum[r-1][0] + 1 else: cum[r][0] = cum[r-1][0] for i in range(1,K+1): if first[r]<=1: dp[r][i] = cum[r-1][i-1] else: dp[r][i] = (cum[r-1][i-1] - cum[first[r]-2][i-1]) % mod cum[r][i] = (cum[r-1][i] + dp[r][i]) % mod #for l in range(first[r],r+1): #dp[r][i] += dp[l-1][i-1] #dp[r][i] %= mod #print(dp[K]) exp_poly = [0 for i in range(K+1)] for i in range(K+1): for j in range(i+1): if j&1: exp_poly[i-j] -= cmb(i,j,mod) * dp[K][i] % mod else: exp_poly[i-j] += cmb(i,j,mod) * dp[K][i] % mod exp_poly[i-j] %= mod res = 0 for i in range(K+1): res += exp_poly[i] * pow(i,N,mod) res %= mod print(res)