結果

問題 No.1646 Avoid Palindrome
ユーザー charmychachachacharmychachacha
提出日時 2021-08-13 22:11:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 380 ms / 3,000 ms
コード長 1,027 bytes
コンパイル時間 1,516 ms
コンパイル使用メモリ 165,784 KB
実行使用メモリ 279,504 KB
最終ジャッジ日時 2024-04-26 03:01:10
合計ジャッジ時間 15,404 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 192 ms
279,264 KB
testcase_01 AC 194 ms
279,272 KB
testcase_02 AC 193 ms
279,396 KB
testcase_03 AC 194 ms
279,140 KB
testcase_04 AC 327 ms
279,496 KB
testcase_05 AC 328 ms
279,500 KB
testcase_06 AC 325 ms
279,376 KB
testcase_07 AC 330 ms
279,496 KB
testcase_08 AC 328 ms
279,496 KB
testcase_09 AC 321 ms
279,368 KB
testcase_10 AC 325 ms
279,496 KB
testcase_11 AC 323 ms
279,368 KB
testcase_12 AC 328 ms
279,500 KB
testcase_13 AC 330 ms
279,240 KB
testcase_14 AC 368 ms
279,368 KB
testcase_15 AC 370 ms
279,496 KB
testcase_16 AC 364 ms
279,364 KB
testcase_17 AC 372 ms
279,240 KB
testcase_18 AC 366 ms
279,236 KB
testcase_19 AC 365 ms
279,500 KB
testcase_20 AC 377 ms
279,496 KB
testcase_21 AC 376 ms
279,496 KB
testcase_22 AC 364 ms
279,368 KB
testcase_23 AC 370 ms
279,368 KB
testcase_24 AC 379 ms
279,500 KB
testcase_25 AC 379 ms
279,380 KB
testcase_26 AC 380 ms
279,504 KB
testcase_27 AC 376 ms
279,504 KB
testcase_28 AC 376 ms
279,368 KB
testcase_29 AC 313 ms
279,244 KB
testcase_30 AC 274 ms
279,372 KB
testcase_31 AC 259 ms
279,244 KB
testcase_32 AC 259 ms
279,376 KB
testcase_33 AC 259 ms
279,504 KB
testcase_34 AC 333 ms
279,380 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 151 ms
279,136 KB
testcase_38 AC 151 ms
279,136 KB
testcase_39 AC 150 ms
279,264 KB
testcase_40 AC 150 ms
279,264 KB
testcase_41 AC 152 ms
279,264 KB
testcase_42 AC 150 ms
279,264 KB
testcase_43 AC 260 ms
279,500 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