結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 kmjpkmjp
提出日時 2021-08-13 22:50:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,669 ms / 3,000 ms
コード長 1,282 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 195,996 KB
実行使用メモリ 288,512 KB
最終ジャッジ日時 2024-04-26 03:23:07
合計ジャッジ時間 41,681 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,820 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 942 ms
272,000 KB
testcase_05 AC 953 ms
272,000 KB
testcase_06 AC 909 ms
262,656 KB
testcase_07 AC 935 ms
272,000 KB
testcase_08 AC 940 ms
274,432 KB
testcase_09 AC 896 ms
260,864 KB
testcase_10 AC 919 ms
267,520 KB
testcase_11 AC 903 ms
260,224 KB
testcase_12 AC 933 ms
271,488 KB
testcase_13 AC 935 ms
274,688 KB
testcase_14 AC 1,521 ms
266,752 KB
testcase_15 AC 1,554 ms
272,128 KB
testcase_16 AC 1,525 ms
265,088 KB
testcase_17 AC 1,591 ms
276,480 KB
testcase_18 AC 1,550 ms
269,440 KB
testcase_19 AC 1,535 ms
267,904 KB
testcase_20 AC 1,553 ms
270,208 KB
testcase_21 AC 1,612 ms
276,352 KB
testcase_22 AC 1,565 ms
267,008 KB
testcase_23 AC 1,609 ms
277,888 KB
testcase_24 AC 1,669 ms
288,512 KB
testcase_25 AC 1,654 ms
288,512 KB
testcase_26 AC 1,653 ms
288,512 KB
testcase_27 AC 1,661 ms
288,384 KB
testcase_28 AC 1,665 ms
288,384 KB
testcase_29 AC 542 ms
288,512 KB
testcase_30 AC 552 ms
288,384 KB
testcase_31 AC 541 ms
288,512 KB
testcase_32 AC 541 ms
288,384 KB
testcase_33 AC 540 ms
288,256 KB
testcase_34 AC 1,667 ms
288,512 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 1 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,940 KB
testcase_43 AC 543 ms
288,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N;
string S;

ll dp[50505][27][27];
const ll mo=998244353;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	dp[0][26][26]=1;
	cin>>N;
	cin>>S;
	FOR(i,N) {
		
		if(S[i]=='?') {
			FOR(y,27) FOR(k,26) if(k!=y) {
				FOR(x,27) if(x!=k) dp[i+1][y][k]+=dp[i][x][y];
				dp[i+1][y][k]%=mo;
			}
		}
		else {
			int c=S[i]-'a';
			FOR(x,27) FOR(y,27) if(c!=x&&c!=y) (dp[i+1][y][c]+=dp[i][x][y])%=mo;
		}
	}
	
	ll ret=0;
	FOR(x,27) FOR(y,27) ret+=dp[N][x][y];
	cout<<ret%mo<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0