結果

問題 No.1646 Avoid Palindrome
ユーザー inksamuraiinksamurai
提出日時 2021-08-13 22:05:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,143 ms / 3,000 ms
コード長 2,607 bytes
コンパイル時間 1,414 ms
コンパイル使用メモリ 110,280 KB
実行使用メモリ 415,488 KB
最終ジャッジ日時 2024-04-26 02:54:59
合計ジャッジ時間 44,812 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 670 ms
391,680 KB
testcase_05 AC 689 ms
391,808 KB
testcase_06 AC 671 ms
378,240 KB
testcase_07 AC 653 ms
391,808 KB
testcase_08 AC 677 ms
395,392 KB
testcase_09 AC 648 ms
376,064 KB
testcase_10 AC 652 ms
385,152 KB
testcase_11 AC 640 ms
374,528 KB
testcase_12 AC 678 ms
391,040 KB
testcase_13 AC 701 ms
395,392 KB
testcase_14 AC 2,004 ms
384,128 KB
testcase_15 AC 2,014 ms
391,680 KB
testcase_16 AC 1,946 ms
381,824 KB
testcase_17 AC 2,032 ms
398,592 KB
testcase_18 AC 1,975 ms
387,840 KB
testcase_19 AC 1,987 ms
385,920 KB
testcase_20 AC 1,986 ms
388,992 KB
testcase_21 AC 2,030 ms
397,952 KB
testcase_22 AC 1,968 ms
384,512 KB
testcase_23 AC 2,031 ms
400,256 KB
testcase_24 AC 2,115 ms
415,360 KB
testcase_25 AC 2,138 ms
415,360 KB
testcase_26 AC 2,134 ms
415,360 KB
testcase_27 AC 2,143 ms
415,360 KB
testcase_28 AC 2,136 ms
415,488 KB
testcase_29 AC 512 ms
415,360 KB
testcase_30 AC 505 ms
415,488 KB
testcase_31 AC 507 ms
415,488 KB
testcase_32 AC 507 ms
415,488 KB
testcase_33 AC 505 ms
415,360 KB
testcase_34 AC 2,137 ms
415,360 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 1 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 AC 505 ms
415,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <functional>
#include <numeric>
#include <iomanip> 
#include <stdio.h>
#include <assert.h>
#include <cstring>
//eolibraries
#define lnf 3999999999999999999
#define inf 999999999
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define make_unique(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define pii pair <int,int>
#define rep(i,n) for(int i = 0 ; i < n ; i++) 
#define drep(i,n) for(int i = n-1 ; i >= 0 ; i--)
#define crep(i,x,n) for(int i = x ; i < n ; i++)
#define vi vector <int> 
#define vec(...) vector<__VA_ARGS__>
#define _3yHSMG9 ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
//eodefine
using namespace std;

const int mxn=12000;

//snuke's modular int
template <ll mod>
struct modularint{
	ll x;
	modularint(ll x=0):x(x%mod){}
	modularint& operator+=(const modularint a){
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator-=(const modularint a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	modularint& operator*=(const modularint a){
		(x *= a.x) %= mod;
		return *this;
	}
	modularint operator+(const modularint a)const{
		modularint res(*this);
		return res+=a;
	}
	modularint operator-(const modularint a)const{
		modularint res(*this);
		return res-=a;
	}
	modularint operator*(const modularint a)const{
		modularint res(*this);
		return res*=a;
	}
	modularint pow(ll n)const{
		modularint res=1,x(*this);
		while(n){
			if(n&1)res*=x;
			x*=x;
			n>>=1;
		}
		return res;
	}
	modularint inv()const{
		return pow(mod-2);
	}
};
using mint=modularint<998244353>;

int main(){
_3yHSMG9;
	int n;
	cin>>n;
	string s;
	cin>>s;
	vec(vec(vec(mint))) dp(n+2,vec(vec(mint))(30,vec(mint)(30)));
	dp[0][0][0]=1;
	rep(i,n){
		rep(x,27){
			rep(y,27){
				// if(x==y) continue;
				if(dp[i][x][y].x==0) continue;
				if(s[i]=='?'){
					crep(now,1,27){
						if(x==now or y==now) continue;
						dp[i+1][y][now]+=dp[i][x][y];
					}
				}else{
					int now=s[i]-'a'+1;
					// if(i==0) cout<<now<<"\n";
					if(x==now or y==now) continue;
					dp[i+1][y][now]+=dp[i][x][y];
				}
			}
		}
	}
	mint ans=0;
	rep(x,27){
		rep(y,27){
			ans+=dp[n][x][y];
		}
	}
	// cout<<dp[1][0][1].x<<"\n";
	cout<<ans.x<<"\n";
//	
	return 0;
}
0