結果

問題 No.1646 Avoid Palindrome
ユーザー ruthenruthen
提出日時 2021-08-13 23:35:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 4,119 bytes
コンパイル時間 2,049 ms
コンパイル使用メモリ 170,288 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 03:38:47
合計ジャッジ時間 67,322 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 1,478 ms
5,376 KB
testcase_05 AC 1,479 ms
5,376 KB
testcase_06 AC 1,426 ms
5,376 KB
testcase_07 AC 1,470 ms
5,376 KB
testcase_08 AC 1,479 ms
5,376 KB
testcase_09 AC 1,403 ms
6,940 KB
testcase_10 AC 1,434 ms
6,944 KB
testcase_11 AC 1,397 ms
6,940 KB
testcase_12 AC 1,471 ms
6,940 KB
testcase_13 AC 1,483 ms
6,940 KB
testcase_14 AC 2,772 ms
6,944 KB
testcase_15 AC 2,848 ms
6,944 KB
testcase_16 AC 2,752 ms
6,944 KB
testcase_17 AC 2,876 ms
6,944 KB
testcase_18 AC 2,803 ms
6,940 KB
testcase_19 AC 2,779 ms
6,940 KB
testcase_20 AC 2,810 ms
6,944 KB
testcase_21 AC 2,879 ms
6,940 KB
testcase_22 AC 2,772 ms
6,944 KB
testcase_23 AC 2,901 ms
6,944 KB
testcase_24 AC 2,990 ms
6,940 KB
testcase_25 TLE -
testcase_26 AC 2,997 ms
6,944 KB
testcase_27 AC 2,997 ms
6,944 KB
testcase_28 TLE -
testcase_29 AC 595 ms
6,944 KB
testcase_30 AC 593 ms
6,940 KB
testcase_31 AC 586 ms
6,948 KB
testcase_32 AC 596 ms
6,944 KB
testcase_33 AC 593 ms
6,948 KB
testcase_34 TLE -
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 596 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

// clang-format off
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using vii = vector<int>;
using vll = vector<ll>;
using vdd = vector<ld>;
using vvii = vector<vector<int>>;
using vvll = vector<vector<ll>>;
using vvdd = vector<vector<ld>>;
using vvvii = vector<vector<vector<int>>>;
using vvvll = vector<vector<vector<ll>>>;
using vvvdd = vector<vector<vector<ld>>>;
template<class T, class U> using P = pair<T, U>;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T> using V3 = vector<vector<vector<T>>>;
template<class T> using pque = priority_queue<T, vector<T>, greater<T>>;
#define _overload3(_1, _2, _3, name, ...) name
#define rep1(n) for (ll i = 0; i < (n); i++)
#define rep2(i, n) for (ll i = 0; i < (n); i++)
#define rep3(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(...) _overload3(__VA_ARGS__, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep2(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rrep3(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(...) _overload3(__VA_ARGS__, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
#define pb push_back
#define endl '\n'
#define popcnt(x) __builtin_popcountll(x)
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end());
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);
const int inf = 1 << 30;
const ll INF = 1ll << 60;
const ld DINF = numeric_limits<ld>::infinity();
const ll mod = 1000000007;
const ll modd = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;
const ll dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const ll dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> T min(const vector<T> &x) { return *min_element(all(x)); }
template<typename T> T max(const vector<T> &x) { return *max_element(all(x)); }
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { return os << "(" << p.fi << ", " << p.se << ")"; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "[ "; for (auto &z : v) os << z << " "; os << "]"; return os; }
#define show(x) cout << #x << " = " << x << endl
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll rem(ll a, ll b) { return (a % b + b) % b; }
// clang-format on

// using mint = modint998244353;

int main() {
    IOS;
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n == 1) {
        cout << ((s[0] == '?') ? 26 : 1) << endl;
        return 0;
    }
    vvll dp1(26, vll(26, 0));
    if (s[0] == '?' && s[1] == '?') {
        rep(i, 26) rep(j, 26) dp1[i][j] = (i == j) ? 0 : 1;
    } else if (s[0] == '?') {
        int j = s[1] - 'a';
        rep(i, 26) dp1[i][j] = (i == j) ? 0 : 1;
    } else if (s[1] == '?') {
        int i = s[0] - 'a';
        rep(j, 26) dp1[i][j] = (i == j) ? 0 : 1;
    } else {
        int i = s[0] - 'a', j = s[1] - 'a';
        dp1[i][j] = (i == j) ? 0 : 1;
    }
    rep(t, 2, n) {
        vvll dp2(26, vll(26, 0));
        if (s[t] == '?') {
            rep(k, 26) {
                rep(i, 26) rep(j, 26) {
                    if (i == j || j == k || i == k) continue;
                    dp2[j][k] = (dp2[j][k] + dp1[i][j]) % modd;
                }
            }
        } else {
            int k = s[t] - 'a';
            rep(i, 26) rep(j, 26) {
                if (i == j || j == k || i == k) continue;
                dp2[j][k] = (dp2[j][k] + dp1[i][j]) % modd;
            }
        }
        rep(i, 26) rep(j, 26) dp1[i][j] = dp2[i][j];
    }
    ll ans = 0;
    rep(i, 26) rep(j, 26) if (i != j) ans += dp1[i][j];
    cout << ans % modd << endl;
    return 0;
}

0