結果
問題 | No.1646 Avoid Palindrome |
ユーザー | nawawan |
提出日時 | 2021-08-13 21:56:45 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,029 bytes |
コンパイル時間 | 2,298 ms |
コンパイル使用メモリ | 210,432 KB |
実行使用メモリ | 320,256 KB |
最終ジャッジ日時 | 2024-10-03 18:41:04 |
合計ジャッジ時間 | 17,745 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 431 ms
301,824 KB |
testcase_05 | AC | 419 ms
301,952 KB |
testcase_06 | AC | 411 ms
291,584 KB |
testcase_07 | AC | 420 ms
301,824 KB |
testcase_08 | AC | 426 ms
304,640 KB |
testcase_09 | AC | 405 ms
289,664 KB |
testcase_10 | AC | 412 ms
296,832 KB |
testcase_11 | AC | 403 ms
288,640 KB |
testcase_12 | AC | 423 ms
301,312 KB |
testcase_13 | AC | 427 ms
304,640 KB |
testcase_14 | AC | 451 ms
295,936 KB |
testcase_15 | AC | 461 ms
301,824 KB |
testcase_16 | AC | 449 ms
294,144 KB |
testcase_17 | AC | 471 ms
307,072 KB |
testcase_18 | AC | 453 ms
298,880 KB |
testcase_19 | AC | 458 ms
297,344 KB |
testcase_20 | AC | 455 ms
299,776 KB |
testcase_21 | AC | 469 ms
306,688 KB |
testcase_22 | AC | 454 ms
296,320 KB |
testcase_23 | AC | 475 ms
308,480 KB |
testcase_24 | AC | 492 ms
320,128 KB |
testcase_25 | AC | 492 ms
320,128 KB |
testcase_26 | AC | 490 ms
320,128 KB |
testcase_27 | AC | 492 ms
320,256 KB |
testcase_28 | AC | 487 ms
320,128 KB |
testcase_29 | AC | 425 ms
320,128 KB |
testcase_30 | AC | 428 ms
320,128 KB |
testcase_31 | AC | 427 ms
320,256 KB |
testcase_32 | AC | 426 ms
320,256 KB |
testcase_33 | AC | 428 ms
320,256 KB |
testcase_34 | AC | 490 ms
320,128 KB |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | AC | 2 ms
5,248 KB |
testcase_37 | AC | 2 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | WA | - |
testcase_40 | AC | 2 ms
5,248 KB |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | AC | 2 ms
5,248 KB |
testcase_43 | AC | 426 ms
320,128 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template<const int MOD> struct modint{ long long val; modint(): val(0) {} modint(long long x){ if(x < 0) val = x % MOD + MOD; else val = x % MOD; } modint(const modint &t){ val = t.val; } modint& operator =(const modint m){ val = m.val; return *this; } modint operator -(){ return modint(-val); } modint& operator-=(const modint &m){ val -= m.val; if(val < 0) val += MOD; return *this; } modint& operator+=(const modint &m){ val += m.val; if(val >= MOD) val -= MOD; return *this; } modint& operator*=(const modint &m){ val *= m.val; val %= MOD; return *this; } modint& operator/=(modint m){ *this *= m.inv(); return *this; } modint inv(){ long long x = 1, y = 0; long long a = val, b = MOD; while(b != 0){ long long t = a / b; a -= t * b; x -= t * y; swap(a, b); swap(x, y); } x %= MOD; if(x < 0) x += MOD; return modint(x); } modint pow(long long k){ long long res = 1; long long v = val; while(k > 0){ if(k & 1) res = res * v % MOD; v = v * v % MOD; k >>= 1; } return modint(res); } bool operator==(const modint &m){ return val == m.val; } modint operator+(const modint &m){ return modint(*this) += m; } modint operator-(const modint &m){ return modint(*this) -= m; } modint operator*(const modint &m){ return modint(*this) *= m; } modint operator/(const modint &m){ return modint(*this) /= m; } bool operator!=(const modint &m){ return modint(*this).val != m.val; } bool operator!=(const int &m){ return modint(*this).val != m; } }; const int MOD = 998244353; using mint = modint<MOD>; int main(){ int N; cin >> N; string S; cin >> S; if(N == 1){ if(S[0] == '?') cout << 26 << endl; else cout << 1 << endl; return 0; } vector<vector<vector<mint>>> dp(N, vector<vector<mint>>(26, vector<mint>(26))); if(S[0] == '?'){ if(S[1] == '?'){ for(int i = 0; i < 26; i++){ for(int j = 0; j < 26; j++){ if(i == j) continue; dp[1][i][j] = 1; } } } else{ for(int i = 0; i < 26; i++){ if(i == S[1] - 'a') continue; dp[1][S[1] - 'a'][i] = 1; } } } else{ if(S[1] == '?'){ for(int i = 0; i < 26; i++){ if(i == S[0] - 'a') continue; dp[1][i][S[0] - 'a'] = 1; } } else{ dp[1][S[1] - 'a'][S[0] - 'a'] = 1; } } for(int i = 2; i < N; i++){ if(S[i] == '?'){ for(int j = 0; j < 26; j++){ mint temp = 0; for(int k = 0; k < 26; k++) { if(j == k) continue; temp += dp[i - 1][j][k]; } for(int k = 0; k < 26; k++){ if(j == k) continue; dp[i][k][j] += temp - dp[i - 1][j][k]; } } } else{ int id = S[i] - 'a'; for(int j = 0; j < 26; j++){ if(id == j) continue; mint temp = 0; for(int k = 0; k < 26; k++){ if(k == id) continue; temp += dp[i - 1][j][k]; } dp[i][id][j] += temp; } } } mint ans = 0; for(int i = 0; i < 26; i++){ for(int j = 0; j < 26; j++){ ans += dp[N - 1][i][j]; } } cout << ans.val << endl; }