結果

問題 No.1646 Avoid Palindrome
ユーザー Nzt3Nzt3
提出日時 2021-08-13 22:36:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 937 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 169,256 KB
実行使用メモリ 142,336 KB
最終ジャッジ日時 2024-04-14 19:01:15
合計ジャッジ時間 43,821 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 322 ms
133,888 KB
testcase_06 RE -
testcase_07 AC 320 ms
134,016 KB
testcase_08 AC 327 ms
135,424 KB
testcase_09 RE -
testcase_10 AC 318 ms
131,840 KB
testcase_11 AC 307 ms
128,256 KB
testcase_12 AC 323 ms
133,760 KB
testcase_13 AC 326 ms
135,168 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 312 ms
141,952 KB
testcase_30 AC 316 ms
142,080 KB
testcase_31 AC 329 ms
142,080 KB
testcase_32 AC 315 ms
141,952 KB
testcase_33 AC 315 ms
141,952 KB
testcase_34 RE -
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
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 2 ms
6,940 KB
testcase_43 AC 312 ms
142,080 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(N+1,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++){
    int sum=0;
    vector<int>moji1(26),moji2(26);
    for(int j=0;j<26*27;j++){
      sum=(sum+dp[i-1][j])%mod;
      moji1[j%26]=(moji1[j%26]+dp[i-1][j])%mod;
      moji2[j/26]=(moji2[j/26]+dp[i-1][j])%mod;
    }
    if(S[i]=='?'){
      for(int j=0;j<26*26;j++){
        if(j%26==j/26)continue;
        dp[i][j]=(moji1[j/26]-dp[i-1][(j%26)*26+(j/26)])%mod;
      }
    }else{
      for(int j=0;j<26;j++){
        if(j==S[i]-'a')continue;
        dp[i][j*26+S[i]-'a']=(moji1[j]-dp[i-1][(S[i]-'a')*26+j])%mod;
      }
    }
  }
  int ans=0;
  for(int i=0;i<26*27;i++){
    ans=(ans+dp[N-1][i])%mod;
  }
  if(ans<0)ans+=mod;
  cout<<ans<<'\n';
}
0