結果

問題 No.1646 Avoid Palindrome
ユーザー 蜜蜂蜜蜂
提出日時 2021-04-13 20:42:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 3,000 ms
コード長 1,640 bytes
コンパイル時間 3,932 ms
コンパイル使用メモリ 229,076 KB
実行使用メモリ 281,068 KB
最終ジャッジ日時 2023-08-08 09:03:10
合計ジャッジ時間 13,609 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 113 ms
280,800 KB
testcase_01 AC 112 ms
280,680 KB
testcase_02 AC 112 ms
280,796 KB
testcase_03 AC 96 ms
280,800 KB
testcase_04 AC 146 ms
280,812 KB
testcase_05 AC 146 ms
280,788 KB
testcase_06 AC 144 ms
280,776 KB
testcase_07 AC 146 ms
281,016 KB
testcase_08 AC 146 ms
280,776 KB
testcase_09 AC 142 ms
280,816 KB
testcase_10 AC 146 ms
280,844 KB
testcase_11 AC 145 ms
280,872 KB
testcase_12 AC 145 ms
280,772 KB
testcase_13 AC 146 ms
280,784 KB
testcase_14 AC 166 ms
280,968 KB
testcase_15 AC 167 ms
280,780 KB
testcase_16 AC 164 ms
280,772 KB
testcase_17 AC 167 ms
280,780 KB
testcase_18 AC 164 ms
280,908 KB
testcase_19 AC 176 ms
281,060 KB
testcase_20 AC 175 ms
280,908 KB
testcase_21 AC 178 ms
280,832 KB
testcase_22 AC 163 ms
280,776 KB
testcase_23 AC 168 ms
281,068 KB
testcase_24 AC 171 ms
280,976 KB
testcase_25 AC 173 ms
280,832 KB
testcase_26 AC 171 ms
280,796 KB
testcase_27 AC 173 ms
280,912 KB
testcase_28 AC 171 ms
280,988 KB
testcase_29 AC 135 ms
280,844 KB
testcase_30 AC 135 ms
281,028 KB
testcase_31 AC 135 ms
280,916 KB
testcase_32 AC 135 ms
280,788 KB
testcase_33 AC 135 ms
280,844 KB
testcase_34 AC 171 ms
280,840 KB
testcase_35 AC 84 ms
280,672 KB
testcase_36 AC 83 ms
280,812 KB
testcase_37 AC 83 ms
280,864 KB
testcase_38 AC 82 ms
280,876 KB
testcase_39 AC 87 ms
280,676 KB
testcase_40 AC 82 ms
280,668 KB
testcase_41 AC 83 ms
280,676 KB
testcase_42 AC 83 ms
280,876 KB
testcase_43 AC 134 ms
280,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 6.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;

#define fi first
#define se second
#define pb push_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)

constexpr ll mod = 998244353;
using mint = modint998244353;

mint dp[105000][26][26]={};

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  string s;
  cin>>n>>s;

  if(n==1){
    if(s=="?")cout<<26<<endl;
    else{
      cout<<1<<endl;
    }
    return 0;
  }

  rep(i,0,26){
    if(s[0]!='?'&&(s[0]-'a')!=i)continue;
    rep(j,0,26){
      if(i==j)continue;
      if(s[1]!='?'&&(s[1]-'a')!=j)continue;
      dp[1][i][j]++;
    }
  }

  rep(i,1,n-1){
    mint dp_sum[26]={};
    rep(j,0,26){
      rep(k,0,26){
        dp_sum[k]+=dp[i][j][k];
      }
    }

    if(s[i+1]=='?'){
      rep(j,0,26){
        rep(k,0,26){
          if(j==k)continue;
          dp[i+1][j][k]=dp_sum[j]-dp[i][k][j];
        }
      }
    }
    else{
      int k=s[i+1]-'a';
      rep(j,0,26){
        if(j==k)continue;
        dp[i+1][j][k]=dp_sum[j]-dp[i][k][j];
      }
    }
  }

  mint ans=0;
  rep(i,0,26){
    rep(j,0,26){
      ans+=dp[n-1][i][j];
    }
  }

  cout<<ans.val()<<endl;
}
0