結果

問題 No.1646 Avoid Palindrome
ユーザー 👑 Nachia
提出日時 2021-08-13 21:45:51
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,232 ms / 3,000 ms
コード長 818 bytes
コンパイル時間 2,393 ms
コンパイル使用メモリ 109,968 KB
最終ジャッジ日時 2025-01-23 18:39:12
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)

using m32 = atcoder::modint998244353;

const i64 MOD = 998244353;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  
  m32 dp[27][27] = {};
  dp[26][26] = 1;
  for(char c : S){
    m32 buf[27][27] = {};
    rep(i,26){
      if(c != '?' && c != 'a' + i) continue;
      rep(j,27) rep(k,27) if(j!=i && k!=i) buf[k][i] += dp[j][k];
    }
    rep(i,27) rep(j,27) dp[i][j] = buf[i][j];
  }
  m32 ans = 0;
  rep(i,27) rep(j,27) ans += dp[i][j];
  cout << ans.val() << endl;
  return 0;
}


struct ios_do_not_sync{
  ios_do_not_sync(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
  }
} ios_do_not_sync_instance;


0