結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 ygussanyygussany
提出日時 2021-08-01 08:43:35
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 393 ms / 3,000 ms
コード長 830 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 32,160 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-26 02:24:06
合計ジャッジ時間 8,779 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 0 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 82 ms
6,944 KB
testcase_05 AC 83 ms
6,940 KB
testcase_06 AC 78 ms
6,940 KB
testcase_07 AC 81 ms
6,940 KB
testcase_08 AC 80 ms
6,940 KB
testcase_09 AC 76 ms
6,940 KB
testcase_10 AC 77 ms
6,940 KB
testcase_11 AC 75 ms
6,940 KB
testcase_12 AC 81 ms
6,940 KB
testcase_13 AC 80 ms
6,940 KB
testcase_14 AC 357 ms
6,944 KB
testcase_15 AC 360 ms
6,944 KB
testcase_16 AC 348 ms
6,940 KB
testcase_17 AC 364 ms
6,940 KB
testcase_18 AC 350 ms
6,940 KB
testcase_19 AC 350 ms
6,944 KB
testcase_20 AC 361 ms
6,940 KB
testcase_21 AC 366 ms
6,940 KB
testcase_22 AC 360 ms
6,940 KB
testcase_23 AC 371 ms
6,940 KB
testcase_24 AC 382 ms
6,940 KB
testcase_25 AC 386 ms
6,940 KB
testcase_26 AC 385 ms
6,940 KB
testcase_27 AC 385 ms
6,940 KB
testcase_28 AC 386 ms
6,940 KB
testcase_29 AC 37 ms
6,940 KB
testcase_30 AC 34 ms
6,944 KB
testcase_31 AC 33 ms
6,940 KB
testcase_32 AC 33 ms
6,944 KB
testcase_33 AC 33 ms
6,940 KB
testcase_34 AC 393 ms
6,940 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 1 ms
6,944 KB
testcase_37 AC 1 ms
6,944 KB
testcase_38 AC 1 ms
6,944 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 1 ms
6,944 KB
testcase_41 AC 1 ms
6,940 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 35 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 998244353;

int main()
{
	int N;
	char S[50001];
	scanf("%d", &N);
	scanf("%s", S);
	
	int i, j, k, l, cur, prev;
	long long dp[2][27][27] = {}, tmp;
	for (i = 0, cur = 1, prev = 0, dp[0][26][26] = 1; i < N; i++, cur ^= 1, prev ^= 1) {
		for (j = 0; j < 27; j++) {
			for (k = 0; k < 27; k++) {
				if (dp[prev][j][k] == 0) continue;
				tmp = dp[prev][j][k] % Mod;
				dp[prev][j][k] = 0;
				if (S[i] == '?') {
					for (l = 0; l < 26; l++) dp[cur][k][l] += tmp;
					if (j != 26) dp[cur][k][j] -= tmp;
					if (k != 26) dp[cur][k][k] -= tmp;
				} else if (S[i] != 'a' + j && S[i] != 'a' + k) dp[cur][k][S[i] - 'a'] += tmp;
			}
		}
	}
	
	long long ans = 0;
	for (i = 0; i < 27; i++) for (j = 0; j < 27; j++) ans += dp[prev][i][j];
	printf("%lld\n", ans % Mod);
	fflush(stdout);
	return 0;
}
0