結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
tabae326
|
| 提出日時 | 2021-08-13 23:01:50 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,238 bytes |
| コンパイル時間 | 2,033 ms |
| コンパイル使用メモリ | 199,756 KB |
| 最終ジャッジ日時 | 2025-01-23 20:52:59 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 WA * 2 |
ソースコード
#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;
#define N 50010
mint dp[N][26][26];
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;
}
if(n == 1) {
cout << 0 << endl;
return;
}
rep(x, 0, 26) {
if(s[0] != '?' && s[0] != 'a' + x) continue;
rep(y, 0, 26) {
if(s[1] != '?' && s[1] != 'a' + y) continue;
if(x == y) continue;
dp[2][x][y] = 1;
}
}
rep(i, 2, n) {
if(s[i] != '?') {
rep(x, 0, 26) {
if(s[i] == 'a' + x) continue;
rep(y, 0, 26) {
if(s[i] == 'a' + y || x == y) continue;
dp[i+1][y][s[i]-'a'] += dp[i][x][y];
}
}
} else {
rep(k, 0, 26) {
rep(x, 0, 26) {
if(k == x) continue;
rep(y, 0, 26) {
if(k == y || x == y) continue;
dp[i+1][y][k] += dp[i][x][y];
}
}
}
}
}
mint ans = 0;
rep(x, 0, 26) rep(y, 0, 26) {
ans += dp[n][x][y];
}
cout << ans.val() << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
tabae326