結果
問題 | No.1646 Avoid Palindrome |
ユーザー | hir355 |
提出日時 | 2021-08-13 22:06:23 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,483 bytes |
コンパイル時間 | 2,036 ms |
コンパイル使用メモリ | 198,564 KB |
実行使用メモリ | 146,176 KB |
最終ジャッジ日時 | 2024-04-26 02:56:33 |
合計ジャッジ時間 | 66,054 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 79 ms
145,996 KB |
testcase_01 | AC | 78 ms
145,960 KB |
testcase_02 | AC | 79 ms
145,900 KB |
testcase_03 | AC | 80 ms
145,972 KB |
testcase_04 | AC | 1,399 ms
146,076 KB |
testcase_05 | AC | 1,418 ms
146,032 KB |
testcase_06 | AC | 1,355 ms
146,096 KB |
testcase_07 | AC | 1,425 ms
145,916 KB |
testcase_08 | AC | 1,416 ms
145,920 KB |
testcase_09 | AC | 1,344 ms
145,988 KB |
testcase_10 | AC | 1,369 ms
146,004 KB |
testcase_11 | AC | 1,342 ms
146,048 KB |
testcase_12 | AC | 1,432 ms
146,048 KB |
testcase_13 | AC | 1,403 ms
145,880 KB |
testcase_14 | AC | 2,674 ms
145,792 KB |
testcase_15 | AC | 2,770 ms
146,072 KB |
testcase_16 | AC | 2,694 ms
145,920 KB |
testcase_17 | AC | 2,799 ms
145,920 KB |
testcase_18 | AC | 2,707 ms
146,048 KB |
testcase_19 | AC | 2,669 ms
145,976 KB |
testcase_20 | AC | 2,707 ms
145,920 KB |
testcase_21 | AC | 2,801 ms
145,792 KB |
testcase_22 | AC | 2,665 ms
146,048 KB |
testcase_23 | AC | 2,767 ms
145,976 KB |
testcase_24 | TLE | - |
testcase_25 | AC | 2,852 ms
145,920 KB |
testcase_26 | AC | 2,882 ms
146,176 KB |
testcase_27 | AC | 2,912 ms
146,048 KB |
testcase_28 | AC | 2,848 ms
145,792 KB |
testcase_29 | AC | 526 ms
145,920 KB |
testcase_30 | AC | 533 ms
146,012 KB |
testcase_31 | AC | 535 ms
146,048 KB |
testcase_32 | AC | 526 ms
145,920 KB |
testcase_33 | AC | 523 ms
145,920 KB |
testcase_34 | AC | 2,870 ms
146,048 KB |
testcase_35 | AC | 78 ms
145,892 KB |
testcase_36 | AC | 79 ms
145,848 KB |
testcase_37 | AC | 84 ms
145,920 KB |
testcase_38 | AC | 80 ms
146,040 KB |
testcase_39 | AC | 80 ms
145,764 KB |
testcase_40 | AC | 79 ms
145,880 KB |
testcase_41 | AC | 79 ms
146,048 KB |
testcase_42 | AC | 80 ms
145,920 KB |
testcase_43 | AC | 547 ms
146,000 KB |
ソースコード
#include <atcoder/modint> #include <bits/stdc++.h> using namespace std; using namespace atcoder; constexpr long long INF_LL = 2000000000000000000LL; constexpr int INF = 2000000000; constexpr long long MOD = 1000000007; #define all(x) x.begin(), x.end() #define REP(i, a, b) for(int i = a; i < b; i++) #define rep(i, n) REP(i, 0, n) typedef long long ll; typedef pair<ll, ll> P; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<P> vp; typedef vector<ll> vl; int dx[4] = {0, -1, 0, 1}; int dy[4] = {1, 0, -1, 0}; int sign[2] = {1, -1}; template <class T> bool chmax(T &a, T b) { if(a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, T b) { if(a > b) { a = b; return 1; } return 0; } ll modpow(ll a, ll b, ll m) { if(b == 0) return 1; ll t = modpow(a, b / 2, m); if(b & 1) { return (t * t % m) * a % m; } else { return t * t % m; } } struct edge { int to; ll cost; edge(int t, ll c) { to = t, cost = c; } }; typedef vector<vector<int>> graph; using mint = modint998244353; // constexpr int MAX_COM = 2001; // mint fac[MAX_COM], ifac[MAX_COM]; // void initfac() { // fac[0] = ifac[0] = 1; // REP(i, 1, MAX_COM) fac[i] = i * fac[i - 1]; // REP(i, 1, MAX_COM) ifac[i] = 1 / fac[i]; // } // mint nCr(int n, int r){ // if(r < 0 || n < r) return 0; // return fac[n] * ifac[n - r] * ifac[r]; // } // typedef ll S; // S op(S x, S y){ return min(x, y); } // S e(){ return INF_LL; } // int mapping(int f, int x){ return f ^ x; } // int composition(int f, int x){ return f ^ x; } // int id(){ return 0; } mint dp[50001][27][27]; int main(){ cin.tie(0); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(16); int n; string s; cin >> n >> s; dp[0][26][26] = 1; rep(i, n){ rep(j, 27){ rep(k, 27){ if(s[i] == '?'){ rep(c, 26){ if(c != j && c != k){ dp[i + 1][k][c] += dp[i][j][k]; } } }else{ if(s[i] - 'a' != j && s[i] - 'a' != k){ dp[i + 1][k][s[i] - 'a'] += dp[i][j][k]; } } } } } mint ans = 0; rep(i, 27) rep(j, 27) ans += dp[n][i][j]; cout << ans.val() << endl; }