結果
問題 | No.2899 Taffy Permutation |
ユーザー | chineristAC |
提出日時 | 2024-09-20 21:49:15 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 141 ms / 2,000 ms |
コード長 | 1,928 bytes |
コンパイル時間 | 278 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-09-20 21:49:26 |
合計ジャッジ時間 | 2,904 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
55,808 KB |
testcase_01 | AC | 47 ms
56,192 KB |
testcase_02 | AC | 50 ms
55,936 KB |
testcase_03 | AC | 48 ms
56,192 KB |
testcase_04 | AC | 49 ms
55,936 KB |
testcase_05 | AC | 45 ms
55,936 KB |
testcase_06 | AC | 46 ms
56,064 KB |
testcase_07 | AC | 47 ms
56,064 KB |
testcase_08 | AC | 47 ms
56,192 KB |
testcase_09 | AC | 121 ms
77,184 KB |
testcase_10 | AC | 119 ms
77,312 KB |
testcase_11 | AC | 128 ms
77,056 KB |
testcase_12 | AC | 141 ms
77,312 KB |
testcase_13 | AC | 141 ms
77,184 KB |
testcase_14 | AC | 141 ms
77,184 KB |
testcase_15 | AC | 135 ms
77,056 KB |
testcase_16 | AC | 135 ms
77,056 KB |
testcase_17 | AC | 135 ms
77,312 KB |
testcase_18 | AC | 47 ms
55,680 KB |
testcase_19 | AC | 132 ms
77,056 KB |
ソースコード
import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) mod = 998244353 def solve(N,S): dp = [0] * (N+1) dp[0] = 1 for idx,s in enumerate(S): ndp = [0] * (N+2) for i in range(N+1): if not dp[i]: continue if s == '0': #ndp[i+1] += i * dp[i] % mod #ndp[i+1] %= mod ndp[i+1] += i * dp[i] % mod ndp[i+2] -= i * dp[i] % mod ndp[i+1] %= mod ndp[i+2] %= mod ndp[i+1] += dp[i] ndp[idx+2] -= dp[i] ndp[i+1] %= mod ndp[idx+2] %= mod #for j in range(i+1,idx+2): #ndp[j] += dp[i] #ndp[j] %= mod else: ndp[i] += dp[i] * (idx-i+1) % mod ndp[i] %= mod ndp[i+1] -= dp[i] * (idx-i+1) % mod ndp[i+1] %= mod dp = ndp for i in range(1,N+2): dp[i] += dp[i-1] dp[i] %= mod return sum(dp) % mod def brute(N,S): res = 0 for p in permutations([i for i in range(N)]): flg = 1 for i in range(N): for j in range(i+1,N): if S[i] == '0' and S[j] == '1' and p[i] > p[j]: flg = 0 res += flg return res while False: N = 8 S = "".join([random.choice("01") for i in range(N)]) #S = input() exp = brute(N,S) res = solve(N,S) if exp!=res: print("WA") print(N) print(S) print(exp,res) exit() else: print("AC",exp) N = int(input()) S = input() print(solve(N,S))