結果

問題 No.1646 Avoid Palindrome
ユーザー Nzt3Nzt3
提出日時 2021-08-13 22:40:18
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 913 bytes
コンパイル時間 1,957 ms
コンパイル使用メモリ 170,924 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-14 19:08:31
合計ジャッジ時間 12,919 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 224 ms
6,940 KB
testcase_06 RE -
testcase_07 AC 221 ms
6,940 KB
testcase_08 AC 226 ms
6,944 KB
testcase_09 RE -
testcase_10 AC 218 ms
6,940 KB
testcase_11 AC 214 ms
6,940 KB
testcase_12 AC 221 ms
6,944 KB
testcase_13 AC 224 ms
6,944 KB
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 AC 204 ms
6,940 KB
testcase_30 AC 207 ms
6,940 KB
testcase_31 AC 202 ms
6,940 KB
testcase_32 AC 203 ms
6,940 KB
testcase_33 AC 203 ms
6,944 KB
testcase_34 RE -
testcase_35 WA -
testcase_36 WA -
testcase_37 RE -
testcase_38 RE -
testcase_39 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 1 ms
6,944 KB
testcase_43 AC 203 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;

int main(){
  int N;
  string S;
  cin>>N>>S;
  vector<vector<int>>dp(2,vector<int>(26*27));
  if(S[0]=='?'){
    for(int i=0;i<26;i++)dp[0][26*26+i]=1;
  }else{
    dp[0][26*26+S[0]-'a']=1;
  }
  for(int i=1;i<N;i++){
    vector<int>moji1(26),moji2(26);
    for(int j=0;j<26*27;j++){
      moji1[j%26]=(moji1[j%26]+dp[0][j])%mod;
      moji2[j/26]=(moji2[j/26]+dp[0][j])%mod;
      dp[1][j]=0;
    }
    if(S[i]=='?'){
      for(int j=0;j<26*26;j++){
        if(j%26==j/26)continue;
        dp[1][j]=(moji1[j/26]-dp[0][(j%26)*26+(j/26)])%mod;
      }
    }else{
      for(int j=0;j<26;j++){
        if(j==S[i]-'a')continue;
        dp[1][j*26+S[i]-'a']=(moji1[j]-dp[0][(S[i]-'a')*26+j])%mod;
      }
    }
    dp[0]=dp[1];
  }
  int ans=0;
  for(int i=0;i<26*27;i++){
    ans=(ans+dp[1][i])%mod;
  }
  if(ans<0)ans+=mod;
  cout<<ans<<'\n';
}
0