結果

問題 No.1646 Avoid Palindrome
ユーザー 蜜蜂蜜蜂
提出日時 2021-04-13 20:42:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 243 ms / 3,000 ms
コード長 1,640 bytes
コンパイル時間 4,510 ms
コンパイル使用メモリ 226,100 KB
実行使用メモリ 281,104 KB
最終ジャッジ日時 2024-04-26 02:22:30
合計ジャッジ時間 15,624 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 166 ms
280,924 KB
testcase_01 AC 170 ms
280,700 KB
testcase_02 AC 167 ms
280,868 KB
testcase_03 AC 167 ms
280,764 KB
testcase_04 AC 224 ms
280,952 KB
testcase_05 AC 224 ms
280,944 KB
testcase_06 AC 225 ms
280,864 KB
testcase_07 AC 224 ms
280,852 KB
testcase_08 AC 230 ms
280,956 KB
testcase_09 AC 225 ms
280,948 KB
testcase_10 AC 224 ms
281,008 KB
testcase_11 AC 220 ms
280,936 KB
testcase_12 AC 225 ms
280,884 KB
testcase_13 AC 227 ms
280,956 KB
testcase_14 AC 238 ms
280,908 KB
testcase_15 AC 236 ms
280,856 KB
testcase_16 AC 235 ms
280,968 KB
testcase_17 AC 239 ms
280,980 KB
testcase_18 AC 237 ms
280,964 KB
testcase_19 AC 240 ms
280,872 KB
testcase_20 AC 240 ms
281,084 KB
testcase_21 AC 239 ms
281,044 KB
testcase_22 AC 237 ms
280,972 KB
testcase_23 AC 238 ms
280,932 KB
testcase_24 AC 241 ms
281,092 KB
testcase_25 AC 242 ms
280,948 KB
testcase_26 AC 242 ms
280,908 KB
testcase_27 AC 243 ms
281,004 KB
testcase_28 AC 243 ms
280,836 KB
testcase_29 AC 217 ms
280,888 KB
testcase_30 AC 219 ms
281,008 KB
testcase_31 AC 222 ms
281,008 KB
testcase_32 AC 221 ms
281,060 KB
testcase_33 AC 221 ms
281,104 KB
testcase_34 AC 243 ms
280,880 KB
testcase_35 AC 167 ms
280,700 KB
testcase_36 AC 169 ms
280,796 KB
testcase_37 AC 170 ms
280,744 KB
testcase_38 AC 168 ms
280,752 KB
testcase_39 AC 167 ms
280,904 KB
testcase_40 AC 168 ms
280,936 KB
testcase_41 AC 170 ms
280,760 KB
testcase_42 AC 167 ms
280,716 KB
testcase_43 AC 218 ms
280,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//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;
}
0