結果
| 問題 |
No.1646 Avoid Palindrome
|
| コンテスト | |
| ユーザー |
蜜蜂
|
| 提出日時 | 2021-04-13 20:42:01 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 280 ms / 3,000 ms |
| コード長 | 1,640 bytes |
| コンパイル時間 | 4,014 ms |
| コンパイル使用メモリ | 230,100 KB |
| 実行使用メモリ | 280,960 KB |
| 最終ジャッジ日時 | 2024-11-08 14:45:40 |
| 合計ジャッジ時間 | 16,923 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 40 |
ソースコード
//g++ 6.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
constexpr ll mod = 998244353;
using mint = modint998244353;
mint dp[105000][26][26]={};
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
string s;
cin>>n>>s;
if(n==1){
if(s=="?")cout<<26<<endl;
else{
cout<<1<<endl;
}
return 0;
}
rep(i,0,26){
if(s[0]!='?'&&(s[0]-'a')!=i)continue;
rep(j,0,26){
if(i==j)continue;
if(s[1]!='?'&&(s[1]-'a')!=j)continue;
dp[1][i][j]++;
}
}
rep(i,1,n-1){
mint dp_sum[26]={};
rep(j,0,26){
rep(k,0,26){
dp_sum[k]+=dp[i][j][k];
}
}
if(s[i+1]=='?'){
rep(j,0,26){
rep(k,0,26){
if(j==k)continue;
dp[i+1][j][k]=dp_sum[j]-dp[i][k][j];
}
}
}
else{
int k=s[i+1]-'a';
rep(j,0,26){
if(j==k)continue;
dp[i+1][j][k]=dp_sum[j]-dp[i][k][j];
}
}
}
mint ans=0;
rep(i,0,26){
rep(j,0,26){
ans+=dp[n-1][i][j];
}
}
cout<<ans.val()<<endl;
}
蜜蜂