結果

問題 No.1646 Avoid Palindrome
ユーザー rk427454171rk427454171
提出日時 2021-08-13 22:11:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,043 bytes
コンパイル時間 1,750 ms
コンパイル使用メモリ 170,812 KB
実行使用メモリ 198,048 KB
最終ジャッジ日時 2024-04-14 18:16:12
合計ジャッジ時間 54,344 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 2,099 ms
187,136 KB
testcase_05 AC 2,072 ms
187,008 KB
testcase_06 AC 2,015 ms
180,736 KB
testcase_07 AC 2,073 ms
186,880 KB
testcase_08 AC 2,095 ms
188,672 KB
testcase_09 AC 1,980 ms
179,584 KB
testcase_10 AC 2,029 ms
183,936 KB
testcase_11 AC 1,969 ms
178,816 KB
testcase_12 AC 2,077 ms
186,624 KB
testcase_13 AC 2,083 ms
188,672 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

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]) % 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