結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
rk427454171
|
| 提出日時 | 2021-08-13 22:11:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,043 bytes |
| コンパイル時間 | 1,844 ms |
| コンパイル使用メモリ | 174,236 KB |
| 実行使用メモリ | 188,800 KB |
| 最終ジャッジ日時 | 2024-10-03 19:27:43 |
| 合計ジャッジ時間 | 32,063 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 10 TLE * 10 -- * 20 |
ソースコード
/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
cerr << "\e[1;33m" << s << " = [";
while(l != r) {
cerr << *l;
cerr << (++l == r ? ']' : ',');
}
cerr << "\e[0m\n";
}
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
/*--------------------------------------------------------------------------------------*/
signed main() { EmiliaMyWife
int n;
cin >> n;
string s;
cin >> s;
vector<vector<vector<int>>> dp(n, vector<vector<int>>(26, vector<int>(27)));
if(s[0] == '?') {
for(int i = 0; i < 26; i++)
dp[0][i][26] = 1;
}
else
dp[0][s[0] - 'a'][26] = 1;
const int mod = 998244353;
for(int i = 1; i < n; i++) {
for(int j = 0; j < 26; j++) {
if(s[i] != '?' && s[i] - 'a' != j)
continue;
for(int k = 0; k < 26; k++) {
if(j == k)
continue;
for(int l = 0; l < 27; l++) {
if(j == l)
continue;
dp[i][j][k] = (dp[i][j][k] + dp[i - 1][k][l]) % mod;
}
}
}
//print(dp[i]);
}
int ans = 0;
for(int i = 0; i < 26; i++)
for(int j = 0; j < 27; j++)
ans = (ans + dp[n - 1][i][j]) % mod;
cout << ans << '\n';
}
rk427454171