結果

問題 No.1646 Avoid Palindrome
ユーザー charmychachachacharmychachacha
提出日時 2021-08-13 22:11:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 3,000 ms
コード長 1,027 bytes
コンパイル時間 1,632 ms
コンパイル使用メモリ 165,260 KB
実行使用メモリ 279,580 KB
最終ジャッジ日時 2023-08-08 09:48:09
合計ジャッジ時間 11,251 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
279,236 KB
testcase_01 AC 114 ms
279,272 KB
testcase_02 AC 112 ms
279,184 KB
testcase_03 AC 175 ms
279,184 KB
testcase_04 AC 200 ms
279,580 KB
testcase_05 AC 197 ms
279,292 KB
testcase_06 AC 194 ms
279,304 KB
testcase_07 AC 196 ms
279,356 KB
testcase_08 AC 198 ms
279,292 KB
testcase_09 AC 193 ms
279,368 KB
testcase_10 AC 197 ms
279,296 KB
testcase_11 AC 193 ms
279,352 KB
testcase_12 AC 197 ms
279,356 KB
testcase_13 AC 198 ms
279,304 KB
testcase_14 AC 239 ms
279,308 KB
testcase_15 AC 241 ms
279,356 KB
testcase_16 AC 238 ms
279,356 KB
testcase_17 AC 241 ms
279,292 KB
testcase_18 AC 239 ms
279,292 KB
testcase_19 AC 239 ms
279,356 KB
testcase_20 AC 239 ms
279,344 KB
testcase_21 AC 243 ms
279,356 KB
testcase_22 AC 245 ms
279,292 KB
testcase_23 AC 247 ms
279,292 KB
testcase_24 AC 251 ms
279,316 KB
testcase_25 AC 253 ms
279,312 KB
testcase_26 AC 252 ms
279,404 KB
testcase_27 AC 251 ms
279,328 KB
testcase_28 AC 254 ms
279,296 KB
testcase_29 AC 169 ms
279,504 KB
testcase_30 AC 170 ms
279,328 KB
testcase_31 AC 167 ms
279,552 KB
testcase_32 AC 168 ms
279,312 KB
testcase_33 AC 171 ms
279,296 KB
testcase_34 AC 252 ms
279,296 KB
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 1 ms
4,384 KB
testcase_37 AC 70 ms
279,184 KB
testcase_38 AC 70 ms
279,220 KB
testcase_39 AC 69 ms
279,248 KB
testcase_40 AC 71 ms
279,428 KB
testcase_41 AC 69 ms
279,436 KB
testcase_42 AC 68 ms
279,232 KB
testcase_43 AC 168 ms
279,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; string S;
	cin >> N >> S;
	if(N == 1 && S == "?"){
		cout << 26 << "\n"; return 0; 
	}else if(N == 1){
		cout << 1 << "\n"; return 0; 
	}
	long long mod = 998244353;
	long long dp[50010][680] = {};
	long long ikkomae[50010][26] = {}; 
	for(int i = 0; i < 676; i++){
		char c1 = 'a' + (i / 26);
		char c2 = 'a' + (i % 26); 
		if(c1 == c2) continue; 
		if(S[0] != '?' && S[0] != c1) continue;
		if(S[1] != '?' && S[1] != c2) continue;
		dp[1][i] = 1;
		ikkomae[1][i % 26] ++; 
	}
	for(int i = 2; i < N; i++){
		for(int j = 0; j < 676; j++){
			char c1 = 'a' + (j / 26);
			char c2 = 'a' + (j % 26);
			if(c1 == c2) continue;
			if(S[i] != '?' && S[i] != c2) continue;
			dp[i][j] = (mod + ikkomae[i-1][j/26] - dp[i-1][26*(j%26)+j/26]) % mod; 
			ikkomae[i][j%26] += dp[i][j];
			ikkomae[i][j%26] %= mod; 
		}
	}
	long long ans = 0; 
	for(int i = 0; i < 676; i++) ans += dp[N-1][i];
	cout << ans % mod << "\n";
}
0