結果

問題 No.1646 Avoid Palindrome
ユーザー Drice27149Drice27149
提出日時 2021-08-14 00:05:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,526 ms / 3,000 ms
コード長 940 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 34,432 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 03:40:49
合計ジャッジ時間 34,218 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 754 ms
6,940 KB
testcase_05 AC 736 ms
6,940 KB
testcase_06 AC 716 ms
6,940 KB
testcase_07 AC 744 ms
6,940 KB
testcase_08 AC 743 ms
6,944 KB
testcase_09 AC 699 ms
6,940 KB
testcase_10 AC 731 ms
6,944 KB
testcase_11 AC 707 ms
6,940 KB
testcase_12 AC 740 ms
6,940 KB
testcase_13 AC 754 ms
6,944 KB
testcase_14 AC 1,407 ms
6,944 KB
testcase_15 AC 1,428 ms
6,940 KB
testcase_16 AC 1,390 ms
6,944 KB
testcase_17 AC 1,444 ms
6,940 KB
testcase_18 AC 1,396 ms
6,940 KB
testcase_19 AC 1,405 ms
6,940 KB
testcase_20 AC 1,419 ms
6,940 KB
testcase_21 AC 1,444 ms
6,944 KB
testcase_22 AC 1,389 ms
6,940 KB
testcase_23 AC 1,452 ms
6,944 KB
testcase_24 AC 1,502 ms
6,940 KB
testcase_25 AC 1,526 ms
6,944 KB
testcase_26 AC 1,499 ms
6,940 KB
testcase_27 AC 1,511 ms
6,940 KB
testcase_28 AC 1,518 ms
6,944 KB
testcase_29 AC 310 ms
6,944 KB
testcase_30 AC 311 ms
6,944 KB
testcase_31 AC 301 ms
6,940 KB
testcase_32 AC 310 ms
6,940 KB
testcase_33 AC 308 ms
6,944 KB
testcase_34 AC 1,509 ms
6,944 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 1 ms
6,944 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 311 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
const long long mod = 998244353;
int f[2][30][30];
char s[50005];

int main(){
	int n;
	scanf("%d%s",&n,s+1);
	int x = 0;
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < 26; j++){
			if(s[1]-'a'!=i && s[1]!='?') continue;
			if(s[2]-'a'!=j && s[2]!='?') continue;
			if(i!=j) f[x][i][j]++;
		}
	}
	if(n==1){
		if(s[1]=='?') printf("26\n");
		else printf("1\n");
		return 0;
	}
	for(int i = 3; i <= n; i++){
		int y = !x;
		for(int a = 0; a < 26; a++){
			for(int b = 0; b < 26; b++){
				f[y][a][b] = 0;
				if(a==b) continue;
				if(s[i]!='?' && s[i]-'a'!=b) continue;
				for(int c = 0; c < 26; c++){
					if(c!=b){
						f[y][a][b] += f[x][c][a];
						if(f[y][a][b] >= mod) f[y][a][b] -= mod;
					}
				}
			}
		}	
		x = y;
	}
	int ans = 0;
	for(int i = 0; i < 26; i++){
		for(int j = 0; j < 26; j++){
			ans += f[x][i][j];
			if(ans >= mod) ans -= mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}
0