結果

問題 No.1646 Avoid Palindrome
ユーザー Nzt3Nzt3
提出日時 2021-08-13 22:53:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 318 ms / 3,000 ms
コード長 1,053 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 169,392 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-26 03:22:23
合計ジャッジ時間 11,846 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,948 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 251 ms
6,944 KB
testcase_05 AC 249 ms
6,940 KB
testcase_06 AC 244 ms
6,944 KB
testcase_07 AC 250 ms
6,940 KB
testcase_08 AC 252 ms
6,944 KB
testcase_09 AC 242 ms
6,940 KB
testcase_10 AC 245 ms
6,944 KB
testcase_11 AC 238 ms
6,944 KB
testcase_12 AC 249 ms
6,940 KB
testcase_13 AC 250 ms
6,944 KB
testcase_14 AC 291 ms
6,940 KB
testcase_15 AC 297 ms
6,940 KB
testcase_16 AC 292 ms
6,944 KB
testcase_17 AC 306 ms
6,940 KB
testcase_18 AC 298 ms
6,944 KB
testcase_19 AC 291 ms
6,940 KB
testcase_20 AC 298 ms
6,940 KB
testcase_21 AC 303 ms
6,940 KB
testcase_22 AC 293 ms
6,940 KB
testcase_23 AC 308 ms
6,944 KB
testcase_24 AC 318 ms
6,944 KB
testcase_25 AC 317 ms
6,940 KB
testcase_26 AC 317 ms
6,944 KB
testcase_27 AC 317 ms
6,940 KB
testcase_28 AC 317 ms
6,940 KB
testcase_29 AC 231 ms
6,940 KB
testcase_30 AC 232 ms
6,940 KB
testcase_31 AC 231 ms
6,944 KB
testcase_32 AC 232 ms
6,940 KB
testcase_33 AC 231 ms
6,940 KB
testcase_34 AC 317 ms
6,940 KB
testcase_35 AC 1 ms
6,940 KB
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 AC 2 ms
6,940 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,944 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 234 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const long long mod=998244353;
int main(){
  long long N;
  string S;
  cin>>N>>S;
  vector<vector<long long>>dp(2,vector<long long>(26*27));
  if(S[0]=='?'){
    for(long long i=0;i<26;i++)dp[0][26*26+i]=1;
  }else{
    dp[0][26*26+int(S[0]-'a')]=1;
  }
  for(long long i=1;i<N;i++){
    vector<long long>moji1(26),moji2(27);
    for(long long 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(long long 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(long long j=0;j<26;j++){
        if(j==int(S[i]-'a'))continue;
        dp[1][j*26+int(S[i]-'a')]=(moji1[j]-dp[0][int(S[i]-'a')*26+j])%mod;
      }
    }
    for(long long j=0;j<26*27;j+=1){
      dp[0][j]=dp[1][j];
    }
  }
  long long ans=0;
  for(long long i=0;i<26*27;i++){
    ans=(ans+dp[0][i])%mod;
  }
  if(ans<0)ans+=mod;
  cout<<ans<<'\n';
}
0