結果

問題 No.1646 Avoid Palindrome
ユーザー 夜
提出日時 2021-08-14 09:40:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,497 bytes
コンパイル時間 867 ms
コンパイル使用メモリ 95,400 KB
実行使用メモリ 355,360 KB
最終ジャッジ日時 2024-04-15 06:55:31
合計ジャッジ時間 24,836 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 711 ms
335,060 KB
testcase_05 AC 655 ms
334,868 KB
testcase_06 AC 621 ms
323,532 KB
testcase_07 AC 646 ms
334,856 KB
testcase_08 AC 659 ms
338,088 KB
testcase_09 AC 622 ms
321,612 KB
testcase_10 AC 635 ms
329,340 KB
testcase_11 AC 616 ms
320,252 KB
testcase_12 AC 643 ms
334,272 KB
testcase_13 AC 658 ms
338,204 KB
testcase_14 AC 705 ms
328,576 KB
testcase_15 AC 712 ms
334,976 KB
testcase_16 AC 696 ms
326,656 KB
testcase_17 AC 721 ms
340,608 KB
testcase_18 AC 706 ms
331,904 KB
testcase_19 AC 699 ms
329,944 KB
testcase_20 AC 711 ms
332,544 KB
testcase_21 AC 723 ms
340,352 KB
testcase_22 AC 703 ms
328,704 KB
testcase_23 AC 731 ms
342,272 KB
testcase_24 AC 760 ms
355,328 KB
testcase_25 AC 753 ms
355,200 KB
testcase_26 AC 773 ms
355,200 KB
testcase_27 AC 753 ms
355,360 KB
testcase_28 AC 752 ms
355,328 KB
testcase_29 AC 671 ms
355,200 KB
testcase_30 AC 671 ms
355,272 KB
testcase_31 AC 671 ms
355,356 KB
testcase_32 AC 673 ms
355,148 KB
testcase_33 AC 671 ms
355,148 KB
testcase_34 AC 755 ms
355,200 KB
testcase_35 RE -
testcase_36 RE -
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,944 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 676 ms
355,176 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long mod = 998244353;
long long dp[50050][30][30] = {};
long long sum1[30] = {};
int main() {
	long long n, co = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < 26; j++) {
			int i1 = i, j1 = j;
			if (s[0] != '?') {
				i1 = s[0] - 'a';
			}
			if (s[1] != '?') {
				j1 = s[1] - 'a';
			}
			if (i1 != j1) {
				dp[2][j1][i1] = 1;
			}
		}
	}
	for (int j = 0; j < 26; j++) {
		for (int k = 0; k < 26; k++) {
			sum1[j] += dp[2][j][k];
		}
	}
	for (int i = 2; i < n; i++) {
		if (s[i] == '?') {
			for (int j = 0; j < 26; j++) {
				for (int k = 0; k < 26; k++) {
					if (j != k) {
						dp[i + 1][j][k] += sum1[k];
						dp[i + 1][j][k] -= dp[i][k][j];
					}
				}
			}
		}
		else {
			for (int j = 0; j < 26; j++) {
				if (s[i] - 'a' != j) {
					dp[i + 1][s[i] - 'a'][j] += sum1[j];
					dp[i + 1][s[i] - 'a'][j] -= dp[i][j][s[i] - 'a'];
				}
			}
		}
		for (int j = 0; j < 26; j++) {
			sum1[j] = 0;
			for (int k = 0; k < 26; k++) {
				dp[i + 1][j][k] %= mod;
				sum1[j] += dp[i + 1][j][k];
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < 26; i++) {
		for (int j = 0; j < 26; j++) {
			ans += dp[n][i][j];
			ans %= mod;
		}
	}
	cout << ans << endl;
}
0