結果

問題 No.1646 Avoid Palindrome
ユーザー umezoumezo
提出日時 2021-08-13 22:56:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,307 ms / 3,000 ms
コード長 1,320 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 199,000 KB
実行使用メモリ 267,776 KB
最終ジャッジ日時 2024-04-26 03:28:13
合計ジャッジ時間 54,088 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 1,198 ms
252,484 KB
testcase_05 AC 1,192 ms
252,544 KB
testcase_06 AC 1,150 ms
243,968 KB
testcase_07 AC 1,189 ms
252,416 KB
testcase_08 AC 1,198 ms
254,848 KB
testcase_09 AC 1,140 ms
242,304 KB
testcase_10 AC 1,158 ms
248,448 KB
testcase_11 AC 1,138 ms
241,408 KB
testcase_12 AC 1,191 ms
251,904 KB
testcase_13 AC 1,216 ms
254,720 KB
testcase_14 AC 2,091 ms
247,552 KB
testcase_15 AC 2,156 ms
252,416 KB
testcase_16 AC 2,096 ms
245,888 KB
testcase_17 AC 2,203 ms
256,768 KB
testcase_18 AC 2,130 ms
250,112 KB
testcase_19 AC 2,111 ms
248,960 KB
testcase_20 AC 2,147 ms
250,752 KB
testcase_21 AC 2,198 ms
256,640 KB
testcase_22 AC 2,136 ms
247,936 KB
testcase_23 AC 2,202 ms
257,920 KB
testcase_24 AC 2,307 ms
267,648 KB
testcase_25 AC 2,299 ms
267,648 KB
testcase_26 AC 2,304 ms
267,520 KB
testcase_27 AC 2,298 ms
267,776 KB
testcase_28 AC 2,278 ms
267,776 KB
testcase_29 AC 594 ms
267,648 KB
testcase_30 AC 590 ms
267,648 KB
testcase_31 AC 586 ms
267,776 KB
testcase_32 AC 590 ms
267,776 KB
testcase_33 AC 590 ms
267,648 KB
testcase_34 AC 2,290 ms
267,648 KB
testcase_35 AC 2 ms
6,940 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 1 ms
6,940 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,940 KB
testcase_42 AC 2 ms
6,944 KB
testcase_43 AC 597 ms
267,520 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){
    if(a!=b) 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(c>=0 && c<26){
      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