結果
問題 | No.1504 ヌメロニム |
ユーザー | convexineq |
提出日時 | 2021-05-11 16:37:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,010 ms / 2,000 ms |
コード長 | 2,411 bytes |
コンパイル時間 | 635 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 148,932 KB |
最終ジャッジ日時 | 2024-09-21 21:45:37 |
合計ジャッジ時間 | 25,030 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
74,112 KB |
testcase_01 | AC | 70 ms
74,496 KB |
testcase_02 | AC | 70 ms
74,624 KB |
testcase_03 | AC | 76 ms
76,928 KB |
testcase_04 | AC | 75 ms
74,368 KB |
testcase_05 | AC | 72 ms
74,624 KB |
testcase_06 | AC | 72 ms
74,368 KB |
testcase_07 | AC | 72 ms
74,624 KB |
testcase_08 | AC | 73 ms
74,368 KB |
testcase_09 | AC | 70 ms
74,496 KB |
testcase_10 | AC | 70 ms
74,624 KB |
testcase_11 | AC | 70 ms
74,368 KB |
testcase_12 | AC | 71 ms
74,496 KB |
testcase_13 | AC | 73 ms
74,240 KB |
testcase_14 | AC | 71 ms
74,496 KB |
testcase_15 | AC | 72 ms
74,752 KB |
testcase_16 | AC | 76 ms
76,160 KB |
testcase_17 | AC | 72 ms
75,392 KB |
testcase_18 | AC | 72 ms
75,776 KB |
testcase_19 | AC | 68 ms
74,496 KB |
testcase_20 | AC | 118 ms
92,032 KB |
testcase_21 | AC | 115 ms
92,288 KB |
testcase_22 | AC | 115 ms
92,504 KB |
testcase_23 | AC | 94 ms
84,608 KB |
testcase_24 | AC | 988 ms
147,696 KB |
testcase_25 | AC | 526 ms
121,420 KB |
testcase_26 | AC | 998 ms
148,424 KB |
testcase_27 | AC | 532 ms
122,428 KB |
testcase_28 | AC | 525 ms
122,568 KB |
testcase_29 | AC | 980 ms
148,276 KB |
testcase_30 | AC | 983 ms
148,276 KB |
testcase_31 | AC | 539 ms
121,848 KB |
testcase_32 | AC | 517 ms
122,288 KB |
testcase_33 | AC | 989 ms
148,120 KB |
testcase_34 | AC | 210 ms
99,220 KB |
testcase_35 | AC | 209 ms
98,876 KB |
testcase_36 | AC | 523 ms
119,684 KB |
testcase_37 | AC | 163 ms
95,360 KB |
testcase_38 | AC | 1,008 ms
148,568 KB |
testcase_39 | AC | 976 ms
148,696 KB |
testcase_40 | AC | 966 ms
148,480 KB |
testcase_41 | AC | 965 ms
148,556 KB |
testcase_42 | AC | 982 ms
148,548 KB |
testcase_43 | AC | 1,010 ms
148,300 KB |
testcase_44 | AC | 1,007 ms
148,932 KB |
testcase_45 | AC | 980 ms
148,676 KB |
testcase_46 | AC | 997 ms
148,684 KB |
testcase_47 | AC | 928 ms
148,436 KB |
testcase_48 | AC | 544 ms
121,860 KB |
testcase_49 | AC | 533 ms
121,292 KB |
testcase_50 | AC | 119 ms
92,032 KB |
testcase_51 | AC | 115 ms
92,032 KB |
testcase_52 | AC | 73 ms
75,392 KB |
testcase_53 | AC | 119 ms
92,032 KB |
testcase_54 | AC | 73 ms
74,752 KB |
testcase_55 | AC | 204 ms
98,848 KB |
testcase_56 | AC | 74 ms
76,288 KB |
testcase_57 | AC | 71 ms
74,624 KB |
testcase_58 | AC | 75 ms
76,160 KB |
testcase_59 | AC | 74 ms
76,160 KB |
testcase_60 | AC | 74 ms
76,160 KB |
ソースコード
SIZE=10**6+1 MOD = 998244353 ROOT = 3 roots = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根 iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元 def untt(a,n): for i in range(n): m = 1<<(n-i-1) for s in range(1<<i): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD w_N = w_N*roots[n-i]%MOD def iuntt(a,n): for i in range(n): m = 1<<i for s in range(1<<(n-i-1)): w_N = 1 s *= m*2 for p in range(m): a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD w_N = w_N*iroots[i+1]%MOD inv = pow((MOD+1)//2,n,MOD) for i in range(1<<n): a[i] = a[i]*inv%MOD def convolution(a,b): la = len(a) lb = len(b) if min(la, lb) <= 50: if la < lb: la,lb = lb,la a,b = b,a res = [0]*(la+lb-1) for i in range(la): for j in range(lb): res[i+j] += a[i]*b[j] res[i+j] %= MOD return res deg = la+lb-2 n = deg.bit_length() N = 1<<n a += [0]*(N-len(a)) b += [0]*(N-len(b)) untt(a,n) untt(b,n) for i in range(N): a[i] = a[i]*b[i]%MOD iuntt(a,n) return a[:deg+1] #inv = [0]*SIZE # inv[j] = j^{-1} mod MOD fac = [0]*SIZE # fac[j] = j! mod MOD finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD fac[0] = fac[1] = 1 finv[0] = finv[1] = 1 for i in range(2,SIZE): fac[i] = fac[i-1]*i%MOD finv[-1] = pow(fac[-1],MOD-2,MOD) for i in range(SIZE-1,0,-1): finv[i-1] = finv[i]*i%MOD #inv[i] = finv[i]*fac[i-1]%MOD def polynomial_Taylor_shift(f,c): N = len(f) f = f[:] g = [1]*N cc = c for i in range(1,N): f[i] = f[i]*fac[i]%MOD g[N-i-1] = cc*finv[i]%MOD cc = cc*c%MOD h = convolution(f,g)[N-1:] for i in range(N): h[i] = h[i]*finv[i]%MOD return h ############################################################### import sys readline = sys.stdin.readline n = int(readline()) s = readline().strip() a = [0]*n b = [0]*n for i in range(n): if s[i]=="i": a[n-1-i] = 1 else: b[i] = 1 p = convolution(a,b)[n:] p = polynomial_Taylor_shift(p,1) ans = 0 for i in p: ans ^= i print(ans)