結果

問題 No.1646 Avoid Palindrome
ユーザー SSRSSSRS
提出日時 2021-08-13 21:28:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,259 bytes
コンパイル時間 1,661 ms
コンパイル使用メモリ 172,164 KB
実行使用メモリ 320,108 KB
最終ジャッジ日時 2023-08-08 09:12:38
合計ジャッジ時間 87,548 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 2,263 ms
301,656 KB
testcase_05 AC 2,254 ms
301,656 KB
testcase_06 AC 2,180 ms
291,372 KB
testcase_07 AC 2,258 ms
301,636 KB
testcase_08 AC 2,271 ms
304,560 KB
testcase_09 AC 2,155 ms
289,456 KB
testcase_10 AC 2,211 ms
296,676 KB
testcase_11 AC 2,159 ms
288,500 KB
testcase_12 AC 2,253 ms
301,156 KB
testcase_13 AC 2,277 ms
304,588 KB
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 1,735 ms
319,904 KB
testcase_30 AC 1,734 ms
320,064 KB
testcase_31 AC 1,738 ms
319,912 KB
testcase_32 AC 1,732 ms
319,916 KB
testcase_33 AC 1,733 ms
319,860 KB
testcase_34 TLE -
testcase_35 AC 1 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1,737 ms
319,912 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;
  if (N == 1){
    if (S[0] == '?'){
      cout << 26 << endl;
    } else {
      cout << 1 << endl;
    }
  } else {
    vector<vector<vector<long long>>> dp(N + 1, vector<vector<long long>>(26, vector<long long>(26, 0)));
    for (int i = 0; i < 26; i++){
      if (S[0] == '?' || S[0] - 'a' == i){
        for (int j = 0; j < 26; j++){
          if (S[1] == '?' || S[1] - 'a' == j){
            if (i != j){
              dp[2][i][j]++;
            }
          }
        }
      }
    }
    for (int i = 2; i < N; i++){
      for (int j = 0; j < 26; j++){
        for (int k = 0; k < 26; k++){
          for (int l = 0; l < 26; l++){
            if (S[i] == '?' || S[i] - 'a' == l){
              if (j != l && k != l){
                dp[i + 1][k][l] += dp[i][j][k];
                if (dp[i + 1][k][l] >= MOD){
                  dp[i + 1][k][l] -= MOD;
                }
              }
            }
          }
        }
      }
    }
    long long ans = 0;
    for (int i = 0; i < 26; i++){
      for (int j = 0; j < 26; j++){
        ans += dp[N][i][j];
      }
    }
    ans %= MOD;
    cout << ans << endl;
  }
}
0