結果
問題 | No.1646 Avoid Palindrome |
ユーザー | sash0 |
提出日時 | 2021-08-28 21:33:22 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,556 ms / 3,000 ms |
コード長 | 2,752 bytes |
コンパイル時間 | 2,656 ms |
コンパイル使用メモリ | 226,840 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-05-01 16:32:01 |
合計ジャッジ時間 | 58,546 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 1,227 ms
5,376 KB |
testcase_05 | AC | 1,211 ms
5,376 KB |
testcase_06 | AC | 1,169 ms
5,376 KB |
testcase_07 | AC | 1,213 ms
5,376 KB |
testcase_08 | AC | 1,224 ms
5,376 KB |
testcase_09 | AC | 1,157 ms
5,376 KB |
testcase_10 | AC | 1,184 ms
5,376 KB |
testcase_11 | AC | 1,154 ms
5,376 KB |
testcase_12 | AC | 1,221 ms
5,376 KB |
testcase_13 | AC | 1,230 ms
5,376 KB |
testcase_14 | AC | 2,357 ms
5,376 KB |
testcase_15 | AC | 2,398 ms
5,376 KB |
testcase_16 | AC | 2,338 ms
5,376 KB |
testcase_17 | AC | 2,441 ms
5,376 KB |
testcase_18 | AC | 2,382 ms
5,376 KB |
testcase_19 | AC | 2,362 ms
5,376 KB |
testcase_20 | AC | 2,389 ms
5,376 KB |
testcase_21 | AC | 2,429 ms
5,376 KB |
testcase_22 | AC | 2,362 ms
5,376 KB |
testcase_23 | AC | 2,466 ms
5,376 KB |
testcase_24 | AC | 2,552 ms
5,376 KB |
testcase_25 | AC | 2,537 ms
5,376 KB |
testcase_26 | AC | 2,551 ms
5,376 KB |
testcase_27 | AC | 2,556 ms
5,376 KB |
testcase_28 | AC | 2,551 ms
5,376 KB |
testcase_29 | AC | 442 ms
5,376 KB |
testcase_30 | AC | 442 ms
5,376 KB |
testcase_31 | AC | 436 ms
5,376 KB |
testcase_32 | AC | 442 ms
5,376 KB |
testcase_33 | AC | 442 ms
5,376 KB |
testcase_34 | AC | 2,555 ms
5,376 KB |
testcase_35 | AC | 2 ms
5,376 KB |
testcase_36 | AC | 2 ms
5,376 KB |
testcase_37 | AC | 2 ms
5,376 KB |
testcase_38 | AC | 2 ms
5,376 KB |
testcase_39 | AC | 2 ms
5,376 KB |
testcase_40 | AC | 2 ms
5,376 KB |
testcase_41 | AC | 2 ms
5,376 KB |
testcase_42 | AC | 2 ms
5,376 KB |
testcase_43 | AC | 443 ms
5,376 KB |
ソースコード
// clang-format off #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mp make_pair #define fst first #define snd second #define forn(i,n) for (int i = 0; i < int(n); i++) #define forn1(i,n) for (int i = 1; i <= int(n); i++) #define popcnt __builtin_popcountll #define ffs __builtin_ffsll #define ctz __builtin_ctzll #define clz __builtin_clz #define clzll __builtin_clzll #define all(a) (a).begin(), (a).end() using namespace std; using namespace __gnu_pbds; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int,int>; using pli = pair<ll,int>; using pil = pair<int,ll>; using pll = pair<ll,ll>; template <typename T> using vec = vector<T>; using vi = vec<int>; using vl = vec<ll>; template <typename T> using que = queue<T>; template <typename T> using deq = deque<T>; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename K, typename V> using ordered_map = tree<K, V, less<K>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> T id(T b) {return b;}; template <typename T> void chmax(T &x, T y) {if (x < y) x = y;} template <typename T> void chmin(T &x, T y) {if (x > y) x = y;} template <typename S, typename K> bool contains(S &s, K k) { return s.find(k) != s.end(); } template <typename T> bool getf(T flag, size_t i) { return (flag>>i) & 1; } template <typename T> T setf(T flag, size_t i) { return flag | (T(1)<<i); } template <typename T> T unsetf(T flag, size_t i) { return flag & ~(T(1)<<i); } void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); } // clang-format on int main() { fastio(); int n; string s; cin >> n >> s; const ll MOD = 998244353; auto idx = [](char c1, char c2) { return (c1 - 'a') * 27 + c2 - 'a'; }; vl dp(27 * 27); dp[27 * 27 - 1] = 1; forn(i, n) { vl temp(27 * 27); for (char c2 = 'a'; c2 <= 'z'; c2++) { if (s[i] == '?' or s[i] == c2) { for (char c0 = 'a'; c0 <= '{'; c0++) { for (char c1 = 'a'; c1 <= '{'; c1++) { if (c0 != c2 and c1 != c2) { temp[idx(c1, c2)] = (temp[idx(c1, c2)] + dp[idx(c0, c1)]) % MOD; } } } } } dp = temp; } ll ans = 0; for (char c0 = 'a'; c0 <= '{'; c0++) { for (char c1 = 'a'; c1 <= '{'; c1++) { ans = (ans + dp[idx(c0, c1)]) % MOD; } } cout << ans << endl; return 0; }