結果
問題 | No.2106 Wild Cacco |
ユーザー | 👑 ygussany |
提出日時 | 2022-09-29 22:42:53 |
言語 | C++17(clang) (17.0.6 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 3,137 bytes |
コンパイル時間 | 453 ms |
コンパイル使用メモリ | 102,732 KB |
実行使用メモリ | 34,588 KB |
最終ジャッジ日時 | 2024-06-10 09:00:14 |
合計ジャッジ時間 | 40,331 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
34,328 KB |
testcase_01 | AC | 10 ms
34,328 KB |
testcase_02 | AC | 11 ms
34,456 KB |
testcase_03 | AC | 11 ms
34,328 KB |
testcase_04 | AC | 11 ms
34,324 KB |
testcase_05 | AC | 10 ms
34,456 KB |
testcase_06 | AC | 11 ms
34,332 KB |
testcase_07 | AC | 11 ms
34,328 KB |
testcase_08 | AC | 11 ms
34,456 KB |
testcase_09 | AC | 11 ms
34,332 KB |
testcase_10 | AC | 11 ms
34,460 KB |
testcase_11 | AC | 1,163 ms
34,332 KB |
testcase_12 | AC | 1,367 ms
34,328 KB |
testcase_13 | AC | 1,540 ms
34,460 KB |
testcase_14 | AC | 1,488 ms
34,452 KB |
testcase_15 | AC | 1,610 ms
34,328 KB |
testcase_16 | AC | 1,868 ms
34,464 KB |
testcase_17 | AC | 1,818 ms
34,328 KB |
testcase_18 | AC | 1,725 ms
34,328 KB |
testcase_19 | AC | 1,770 ms
34,328 KB |
testcase_20 | AC | 1,759 ms
34,460 KB |
testcase_21 | AC | 1,798 ms
34,588 KB |
testcase_22 | AC | 1,688 ms
34,460 KB |
testcase_23 | AC | 1,722 ms
34,328 KB |
testcase_24 | AC | 1,603 ms
34,460 KB |
testcase_25 | AC | 1,813 ms
34,328 KB |
testcase_26 | TLE | - |
testcase_27 | AC | 1,870 ms
34,456 KB |
testcase_28 | AC | 1,976 ms
34,456 KB |
testcase_29 | AC | 1 ms
6,940 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 1,623 ms
34,328 KB |
testcase_32 | AC | 1,782 ms
34,324 KB |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
ソースコード
#include <stdio.h> const int Mod = 998244353; int naive(char s[]) { int l; for (l = 0; s[l] != 0; l++); if (l % 2 != 0) return 0; long long dp[1001][2002] = {}, tmp; int i, j, k, ll = l / 2; for (k = 0, dp[0][0] = 1; k < ll; k++) { if (s[k] == '(') { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dp[i][j] % Mod; dp[i][j] = 0; dp[i][j+1] += tmp; } } } else if (s[k] == ')') { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dp[i][j] % Mod; dp[i][j] = 0; if (j > i * 2) dp[i][j-1] += tmp; else if (i > 0) dp[i-1][j-1] += tmp; } } } else if (s[k] == '?') { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dp[i][j] % Mod; dp[i][j] = 0; if (j > i * 2) dp[i+1][j+1] += tmp; else dp[i][j+1] += tmp; } } } else { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dp[i][j] % Mod; dp[i][j] = 0; dp[i][j+1] += tmp; if (j > i * 2) { dp[i][j-1] += tmp; dp[i+1][j+1] += tmp; } else { if (i > 0) dp[i-1][j-1] += tmp; dp[i][j+1] += tmp; } } } } } long long dpp[1001][2002] = {}; for (k = 0, dpp[0][0] = 1; k < ll; k++) { if (s[l-k-1] == ')') { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dpp[i][j] % Mod; dpp[i][j] = 0; dpp[i][j+1] += tmp; } } } else if (s[l-k-1] == '(') { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dpp[i][j] % Mod; dpp[i][j] = 0; if (j > i * 2) dpp[i][j-1] += tmp; else if (i > 0) dpp[i-1][j-1] += tmp; } } } else if (s[l-k-1] == '?') { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dpp[i][j] % Mod; dpp[i][j] = 0; if (j > i * 2) dpp[i+1][j+1] += tmp; else dpp[i][j+1] += tmp; } } } else { for (i = 0; i <= k / 2; i++) { for (j = i * 2 + k % 2; j <= k; j += 2) { tmp = dpp[i][j] % Mod; dpp[i][j] = 0; dpp[i][j+1] += tmp; if (j > i * 2) { dpp[i][j-1] += tmp; dpp[i+1][j+1] += tmp; } else { if (i > 0) dpp[i-1][j-1] += tmp; dpp[i][j+1] += tmp; } } } } } long long ans = 0, dpp_sum[2][2003] = {}; for (i = 0; i <= ll / 2; i++) { for (j = i * 2 + ll % 2; j <= ll; j += 2) { dpp_sum[0][j] += dpp[i][j]; dpp_sum[1][j-i*2] += dpp[i][j]; } } for (j = ll % 2 + 2; j <= ll; j += 2) dpp_sum[0][j] += dpp_sum[0][j-2]; for (j = ll - 2; j >= 0; j -= 2) dpp_sum[1][j] += dpp_sum[1][j+2]; for (i = 0; i <= ll / 2; i++) { for (j = i * 2 + ll % 2; j <= ll; j += 2) { if (j == i * 2 + ll % 2) ans += dp[i][j] * ((dpp_sum[0][ll] - dpp_sum[1][j+2]) % Mod) % Mod; else ans += dp[i][j] * ((dpp_sum[0][ll] - dpp_sum[0][j-i*2-2] - dpp_sum[1][j+2]) % Mod) % Mod; } } return ans % Mod; } int main() { int i; char s[4001]; scanf("%s", s); printf("%d\n", naive(s)); fflush(stdout); return 0; }