結果

問題 No.1646 Avoid Palindrome
ユーザー rk427454171rk427454171
提出日時 2021-08-13 22:14:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,011 ms / 3,000 ms
コード長 2,091 bytes
コンパイル時間 1,629 ms
コンパイル使用メモリ 172,768 KB
実行使用メモリ 198,320 KB
最終ジャッジ日時 2023-08-08 09:50:32
合計ジャッジ時間 48,270 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1,090 ms
186,704 KB
testcase_05 AC 1,081 ms
186,800 KB
testcase_06 AC 1,046 ms
180,404 KB
testcase_07 AC 1,087 ms
186,800 KB
testcase_08 AC 1,095 ms
188,628 KB
testcase_09 AC 1,037 ms
179,384 KB
testcase_10 AC 1,061 ms
183,800 KB
testcase_11 AC 1,030 ms
178,584 KB
testcase_12 AC 1,089 ms
186,460 KB
testcase_13 AC 1,101 ms
188,628 KB
testcase_14 AC 1,863 ms
183,372 KB
testcase_15 AC 1,892 ms
186,740 KB
testcase_16 AC 1,844 ms
182,020 KB
testcase_17 AC 1,923 ms
189,876 KB
testcase_18 AC 1,874 ms
184,928 KB
testcase_19 AC 1,863 ms
184,120 KB
testcase_20 AC 1,877 ms
185,460 KB
testcase_21 AC 1,927 ms
189,700 KB
testcase_22 AC 1,857 ms
183,348 KB
testcase_23 AC 1,931 ms
190,672 KB
testcase_24 AC 2,007 ms
198,124 KB
testcase_25 AC 2,005 ms
198,096 KB
testcase_26 AC 2,000 ms
198,140 KB
testcase_27 AC 2,010 ms
198,124 KB
testcase_28 AC 2,011 ms
198,092 KB
testcase_29 AC 570 ms
198,152 KB
testcase_30 AC 575 ms
198,152 KB
testcase_31 AC 566 ms
198,136 KB
testcase_32 AC 567 ms
198,320 KB
testcase_33 AC 571 ms
198,272 KB
testcase_34 AC 2,005 ms
198,148 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 572 ms
198,056 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
	cerr << "\e[1;33m" << s << " = [";
	while(l != r) {
		cerr << *l;
		cerr << (++l == r ? ']' : ',');
	}
	cerr << "\e[0m\n";
}

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*--------------------------------------------------------------------------------------*/

signed main() { EmiliaMyWife
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<vector<vector<int>>> dp(n, vector<vector<int>>(26, vector<int>(27)));
	if(s[0] == '?') {
		for(int i = 0; i < 26; i++)
			dp[0][i][26] = 1;
	}
	else
		dp[0][s[0] - 'a'][26] = 1;
	const int mod = 998244353;
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < 26; j++) {
			if(s[i] != '?' && s[i] - 'a' != j)
				continue;
			for(int k = 0; k < 26; k++) {
				if(j == k)
					continue;
				for(int l = 0; l < 27; l++) {
					if(j == l)
						continue;
					dp[i][j][k] = (dp[i][j][k] + dp[i - 1][k][l]);
					if(dp[i][j][k] >= mod)
						dp[i][j][k] -= mod;
				}
			}
		}
		//print(dp[i]);
	}
	int ans = 0;
	for(int i = 0; i < 26; i++)
		for(int j = 0; j < 27; j++)
			ans = (ans + dp[n - 1][i][j]) % mod;
	cout << ans << '\n';
}
0