結果

問題 No.1646 Avoid Palindrome
ユーザー tabae326tabae326
提出日時 2021-08-13 22:36:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,401 bytes
コンパイル時間 2,548 ms
コンパイル使用メモリ 208,124 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-04-14 18:58:39
合計ジャッジ時間 3,953 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 11 ms
7,168 KB
testcase_35 WA -
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

// For debug
// Ref: https://qiita.com/ysuzuki19/items/d89057d65284ba1a16ac
#define dump(var)  do{std::cerr << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cerr << e << "\n";}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cerr << e << " "; } std::cerr << "\n";}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ std::cerr << "\n"; for(const auto& v : vv){ view(v); } }
template<typename T> void dump_cout(const T& v) { for(long long i = 0; i < v.size(); i++) std::cout << v[i] << (i == v.size()-1 ? "\n" : " "); }

#include <atcoder/modint>
using mint = atcoder::modint998244353;

void solve() {
    ll n;
    string s;
    cin >> n >> s;
    bool f = true;
    for(auto e : s) if(e == '?') f = false;
    if(f) {
        cout << (s == string(s.rbegin(), s.rend()) ? 0 : 1) << endl;
        return;
    }
    vector<ll> cnt(n, 0);
    vector ok(n, vector<bool>(26, true));
    rep(i, 0, n) {
        if(i+1 <= n-1 && s[i] != '?' && s[i] == s[i+1]) {
            cout << 0 << endl;
            return;
        }
        if(s[i] == '?') {
            if(i+1 <= n-1) {
                if(s[i+1] == '?') cnt[i+1]++;
                else ok[i][s[i+1] - 'a'] = false;
            }
            if(i-1 >= 0) {
                if(s[i-1] != '?') ok[i][s[i-1] - 'a'] = false;
            }
        }
        for(ll j = 1; i - j >= 0 && i + j <= n-1; j++) {
            if(s[i-j] == '?' && s[i+j] == '?') {
                cnt[i+j]++;
                break;
            } else if(s[i-j] == '?') {
                ok[i-j][s[i+j] - 'a'] = false;
                break;
            } else if(s[i+j] == '?') {
                ok[i+j][s[i-j] - 'a'] = false;
                break;
            } else if(s[i-j] != s[i+j]) {
                break;
            } else {
                cout << 0 << endl;
                return;
            }
        }
    }
    mint ans = 1;
    rep(i, 0, n) {
        if(s[i] != '?') continue;
        ll tmp = 0;
        rep(j, 0, 26) if(ok[i][j]) tmp++;
        tmp -= cnt[i];
        ans *= max(0LL, tmp);
    }
    cout << ans.val() << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
0