結果

問題 No.1646 Avoid Palindrome
ユーザー 沙耶花沙耶花
提出日時 2021-08-13 21:27:00
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,629 ms / 3,000 ms
コード長 691 bytes
コンパイル時間 4,684 ms
コンパイル使用メモリ 264,144 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-08 09:10:09
合計ジャッジ時間 53,804 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 618 ms
4,380 KB
testcase_05 AC 615 ms
4,376 KB
testcase_06 AC 590 ms
4,380 KB
testcase_07 AC 610 ms
4,380 KB
testcase_08 AC 611 ms
4,384 KB
testcase_09 AC 578 ms
4,380 KB
testcase_10 AC 589 ms
4,376 KB
testcase_11 AC 577 ms
4,376 KB
testcase_12 AC 617 ms
4,380 KB
testcase_13 AC 612 ms
4,384 KB
testcase_14 AC 2,415 ms
4,380 KB
testcase_15 AC 2,461 ms
4,380 KB
testcase_16 AC 2,401 ms
4,380 KB
testcase_17 AC 2,508 ms
4,376 KB
testcase_18 AC 2,440 ms
4,384 KB
testcase_19 AC 2,432 ms
4,380 KB
testcase_20 AC 2,449 ms
4,380 KB
testcase_21 AC 2,510 ms
4,508 KB
testcase_22 AC 2,417 ms
4,376 KB
testcase_23 AC 2,520 ms
4,380 KB
testcase_24 AC 2,614 ms
4,380 KB
testcase_25 AC 2,629 ms
4,380 KB
testcase_26 AC 2,614 ms
4,380 KB
testcase_27 AC 2,620 ms
4,376 KB
testcase_28 AC 2,617 ms
4,376 KB
testcase_29 AC 137 ms
4,384 KB
testcase_30 AC 137 ms
4,380 KB
testcase_31 AC 136 ms
4,380 KB
testcase_32 AC 138 ms
4,376 KB
testcase_33 AC 139 ms
4,376 KB
testcase_34 AC 2,624 ms
4,380 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 137 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	
	int n;
	cin>>n;
	
	string s;
	cin>>s;
	
	vector dp(27,vector<mint>(27,0));
	dp[26][26] = 1;
	
	rep(i,n){
		vector ndp(27,vector<mint>(27,0));
		
		rep(j,27){
			rep(k,27){
				if(dp[j][k]==0)continue;
				rep(l,26){
					if(l==j||l==k)continue;
					if(s[i] != '?' && s[i] != 'a' + l)continue;
					ndp[k][l] += dp[j][k];
				}
				
			}
		}
		swap(dp,ndp);
	}
	
	mint ans = 0;
	rep(i,27){
		rep(j,27)ans += dp[i][j];
	}
	
	cout<<ans.val()<<endl;
	
	return 0;
}
0