結果

問題 No.1646 Avoid Palindrome
ユーザー karinohitokarinohito
提出日時 2021-08-13 21:54:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,539 ms / 3,000 ms
コード長 1,445 bytes
コンパイル時間 1,577 ms
コンパイル使用メモリ 171,240 KB
実行使用メモリ 320,384 KB
最終ジャッジ日時 2024-04-26 02:49:11
合計ジャッジ時間 59,753 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 1,372 ms
301,952 KB
testcase_05 AC 1,374 ms
302,080 KB
testcase_06 AC 1,335 ms
291,712 KB
testcase_07 AC 1,379 ms
301,952 KB
testcase_08 AC 1,375 ms
304,640 KB
testcase_09 AC 1,325 ms
289,792 KB
testcase_10 AC 1,345 ms
296,832 KB
testcase_11 AC 1,299 ms
288,640 KB
testcase_12 AC 1,348 ms
301,440 KB
testcase_13 AC 1,371 ms
304,768 KB
testcase_14 AC 2,249 ms
295,936 KB
testcase_15 AC 2,331 ms
301,824 KB
testcase_16 AC 2,224 ms
294,272 KB
testcase_17 AC 2,337 ms
307,072 KB
testcase_18 AC 2,270 ms
298,880 KB
testcase_19 AC 2,321 ms
297,472 KB
testcase_20 AC 2,370 ms
299,776 KB
testcase_21 AC 2,428 ms
306,688 KB
testcase_22 AC 2,333 ms
296,320 KB
testcase_23 AC 2,436 ms
308,480 KB
testcase_24 AC 2,527 ms
320,256 KB
testcase_25 AC 2,521 ms
320,256 KB
testcase_26 AC 2,527 ms
320,256 KB
testcase_27 AC 2,537 ms
320,256 KB
testcase_28 AC 2,538 ms
320,128 KB
testcase_29 AC 808 ms
320,256 KB
testcase_30 AC 807 ms
320,256 KB
testcase_31 AC 793 ms
320,256 KB
testcase_32 AC 798 ms
320,384 KB
testcase_33 AC 804 ms
320,384 KB
testcase_34 AC 2,539 ms
320,256 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 811 ms
320,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#include <atcoder/all>
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
//using namespace atcoder;
using ll = long long;
#define all(A) A.begin(),A.end()
using vll = vector<ll>;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using Graph = vector<vector<ll>>;



int main() {
	ll N;
	string S;
	ll mod=998244353;
	cin>>N>>S;
	vector<vector<vll>> DP(N+1,vector<vll> (26,vll(26,0)));
	if(N==1){
		if(S[0]=='?')cout<<26<<endl;
		else cout<<1<<endl;
		return 0;
	}
	if(S[0]=='?'){
		if(S[1]=='?'){
			rep(i,26)rep(j,26)
			{
				if(i==j)continue;
				DP[2][i][j]=1;
			}
		}
		else{
			rep(i,26){
				if(S[1]-'a'==i)continue;
				DP[2][i][S[1]-'a']=1;
			}
		}
	}
	else{
		if(S[1]=='?'){
			rep(i,26){
				if(S[0]-'a'==i)continue;
				DP[2][S[0]-'a'][i]=1;
			}
		}
		else{
			if(S[0]==S[1]){
				cout<<0<<endl;
				return 0;
			}
			DP[2][S[0]-'a'][S[1]-'a']=1;
		}
	}

	for(ll n=2;n<S.size();n++){
		if(S[n]=='?'){
			rep(i,26){
				rep(j,26){
					if(i==j)continue;
					rep(k,26){
						if(i==k||j==k)continue;
						DP[n+1][j][k]+=DP[n][i][j];
						DP[n+1][j][k]%=mod;
					}
				}
			}
		}
		else{
			rep(i,26){
				rep(j,26){
					if(i==j)continue;
					if(i==S[n]-'a')continue;
					if(j==S[n]-'a')continue;
					DP[n+1][j][S[n]-'a']+=DP[n][i][j];
					DP[n+1][j][S[n]-'a']%=mod;
				}
			}
		}

	}
	ll an=0;
	rep(i,26){
		rep(j,26){
			if(i==j)continue;
			an+=DP[N][i][j];
		}

	}
	cout<<an%mod<<endl;
	
}
0