結果
問題 |
No.1646 Avoid Palindrome
|
ユーザー |
👑 ![]() |
提出日時 | 2024-04-26 18:18:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 968 ms / 3,000 ms |
コード長 | 660 bytes |
コンパイル時間 | 487 ms |
コンパイル使用メモリ | 76,440 KB |
最終ジャッジ日時 | 2025-02-21 09:09:57 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 40 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <atcoder/modint> using namespace std; #define rep(i,n) for(int i=0; i<(n); i++) using m32 = atcoder::modint998244353; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int N; cin >> N; string S; cin >> S; m32 dp[27][27] = {}; dp[26][26] = 1; for(char c : S){ m32 buf[27][27] = {}; rep(i,26){ if(c != '?' && c != 'a' + i) continue; rep(j,27) rep(k,27) if(j!=i && k!=i) buf[k][i] += dp[j][k]; } rep(i,27) rep(j,27) dp[i][j] = buf[i][j]; } m32 ans = 0; rep(i,27) rep(j,27) ans += dp[i][j]; cout << ans.val() << endl; return 0; }