結果
問題 | No.2899 Taffy Permutation |
ユーザー | chineristAC |
提出日時 | 2024-09-20 21:46:39 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,693 bytes |
コンパイル時間 | 216 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 77,312 KB |
最終ジャッジ日時 | 2024-09-20 21:46:55 |
合計ジャッジ時間 | 2,608 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | AC | 43 ms
55,424 KB |
testcase_04 | AC | 42 ms
55,680 KB |
testcase_05 | AC | 46 ms
55,680 KB |
testcase_06 | AC | 41 ms
55,552 KB |
testcase_07 | AC | 42 ms
55,552 KB |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 129 ms
76,928 KB |
testcase_13 | AC | 132 ms
77,312 KB |
testcase_14 | AC | 128 ms
77,056 KB |
testcase_15 | AC | 124 ms
77,184 KB |
testcase_16 | WA | - |
testcase_17 | AC | 125 ms
76,800 KB |
testcase_18 | WA | - |
testcase_19 | AC | 127 ms
77,184 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+1): 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 N = int(input()) #S = "".join([random.choice("01") for i in range(N)]) S = input() print(solve(N,S))