結果

問題 No.1646 Avoid Palindrome
ユーザー eve__fuyuki
提出日時 2024-09-06 03:12:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,457 ms / 3,000 ms
コード長 745 bytes
コンパイル時間 2,074 ms
コンパイル使用メモリ 202,324 KB
最終ジャッジ日時 2025-02-24 03:55:38
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void fast_io() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
}

#include <atcoder/modint>
using mint = atcoder::modint998244353;
int main() {
	fast_io();
	int n;
	string s;
	cin >> n >> s;
	vector dp(n + 1, vector(27, vector<mint>(27)));
	dp[0][26][26] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 27; j++) {
			for (int k = 0; k < 27; k++) {
				for (int l = 0; l < 26; l++) {
					if (j == l || k == l) {
						continue;
					}
					if (s[i] == '?' || s[i] == 'a' + l) {
						dp[i + 1][k][l] += dp[i][j][k];
					}
				}
			}
		}
	}
	mint ans = 0;
	for (int i = 0; i < 27; i++) {
		for (int j = 0; j < 27; j++) {
			ans += dp[n][i][j];
		}
	}
	cout << ans.val() << endl;
}
0