結果

問題 No.1646 Avoid Palindrome
ユーザー umezoumezo
提出日時 2021-08-13 22:43:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,312 bytes
コンパイル時間 2,124 ms
コンパイル使用メモリ 199,224 KB
実行使用メモリ 267,776 KB
最終ジャッジ日時 2024-04-14 19:15:14
合計ジャッジ時間 51,694 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 1,155 ms
252,416 KB
testcase_05 AC 1,150 ms
252,416 KB
testcase_06 AC 1,118 ms
243,968 KB
testcase_07 AC 1,148 ms
252,416 KB
testcase_08 AC 1,152 ms
254,720 KB
testcase_09 AC 1,095 ms
242,432 KB
testcase_10 AC 1,129 ms
248,320 KB
testcase_11 AC 1,093 ms
241,280 KB
testcase_12 AC 1,150 ms
251,904 KB
testcase_13 AC 1,157 ms
254,720 KB
testcase_14 AC 1,995 ms
247,680 KB
testcase_15 AC 2,036 ms
252,544 KB
testcase_16 AC 1,986 ms
246,272 KB
testcase_17 AC 2,069 ms
256,896 KB
testcase_18 AC 2,012 ms
249,984 KB
testcase_19 AC 2,011 ms
248,832 KB
testcase_20 AC 2,016 ms
250,752 KB
testcase_21 AC 2,071 ms
256,512 KB
testcase_22 AC 1,996 ms
247,680 KB
testcase_23 AC 2,074 ms
257,920 KB
testcase_24 AC 2,173 ms
267,520 KB
testcase_25 AC 2,167 ms
267,776 KB
testcase_26 AC 2,162 ms
267,776 KB
testcase_27 AC 2,161 ms
267,648 KB
testcase_28 AC 2,158 ms
267,776 KB
testcase_29 AC 589 ms
267,520 KB
testcase_30 AC 580 ms
267,648 KB
testcase_31 AC 575 ms
267,520 KB
testcase_32 AC 581 ms
267,776 KB
testcase_33 AC 581 ms
267,776 KB
testcase_34 AC 2,162 ms
267,776 KB
testcase_35 AC 2 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 2 ms
6,944 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 WA -
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 587 ms
267,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
ll dp[50050][26][26];

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  int n;
  string s;
  cin>>n>>s;
  s='$'+s;
  
  if(n==1){
    if(s[1]=='?') cout<<26<<endl;
    else cout<<1<<endl;
    return 0;
  }
  
  int a=s[1]-'a',b=s[2]-'a';
  if(a>=0 && a<26 && b>=0 && b<26) dp[2][a][b]=1;
  else if(a>=0 && a<26){
    rep(i,26){
      if(i!=a) dp[2][a][i]=1;
    }
  }
  else if(b>=0 && b<26){
    rep(i,26){
      if(i!=b) dp[2][i][b]=1;
    }
  }
  else{
    rep(i,26){
      rep(j,26){
        if(i==j) continue;
        dp[2][i][j]=1;
      }
    }
  }
  
  for(int i=3;i<=n;i++){
    int c=s[i]-'a';
    if(s[i]>='a' && s[i]<='z'){
      rep(j,26){
        if(j==c) continue;
        rep(k,26){
          if(k==c) continue;
          dp[i][k][c]=(dp[i][k][c]+dp[i-1][j][k])%MOD;
        }
      }
    }
    else{
      rep(j,26){
        rep(k,26){
          rep(l,26){
            if(l==j || l==k) continue;
            dp[i][k][l]=(dp[i][k][l]+dp[i-1][j][k])%MOD;
          }
        }
      }
    }
  }
  ll ans=0;
  rep(i,26){
    rep(j,26) ans=(ans+dp[n][i][j])%MOD;
  }
  cout<<ans<<endl;
  
  return 0;
}
0