結果

問題 No.1646 Avoid Palindrome
ユーザー inksamuraiinksamurai
提出日時 2021-08-13 22:03:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,573 bytes
コンパイル時間 1,381 ms
コンパイル使用メモリ 111,256 KB
実行使用メモリ 415,488 KB
最終ジャッジ日時 2024-04-14 18:02:48
合計ジャッジ時間 60,671 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 789 ms
391,680 KB
testcase_05 WA -
testcase_06 AC 746 ms
378,112 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 736 ms
375,936 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2,827 ms
384,128 KB
testcase_15 AC 2,884 ms
391,680 KB
testcase_16 AC 2,822 ms
381,824 KB
testcase_17 AC 2,932 ms
398,464 KB
testcase_18 AC 2,865 ms
387,968 KB
testcase_19 AC 2,843 ms
386,048 KB
testcase_20 AC 2,861 ms
389,120 KB
testcase_21 AC 2,938 ms
397,952 KB
testcase_22 AC 2,830 ms
384,640 KB
testcase_23 AC 2,952 ms
400,128 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 TLE -
testcase_35 WA -
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
権限があれば一括ダウンロードができます

ソースコード

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<<ans.x<<"\n";
//	
	return 0;
}
0