結果

問題 No.1646 Avoid Palindrome
ユーザー chocoruskchocorusk
提出日時 2021-08-13 22:15:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,866 ms / 3,000 ms
コード長 1,261 bytes
コンパイル時間 3,379 ms
コンパイル使用メモリ 188,332 KB
実行使用メモリ 146,104 KB
最終ジャッジ日時 2023-08-08 09:53:36
合計ジャッジ時間 46,222 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
145,840 KB
testcase_01 AC 39 ms
145,772 KB
testcase_02 AC 38 ms
146,104 KB
testcase_03 AC 39 ms
145,840 KB
testcase_04 AC 928 ms
145,940 KB
testcase_05 AC 919 ms
145,920 KB
testcase_06 AC 891 ms
145,960 KB
testcase_07 AC 925 ms
145,936 KB
testcase_08 AC 926 ms
145,888 KB
testcase_09 AC 879 ms
145,908 KB
testcase_10 AC 901 ms
145,884 KB
testcase_11 AC 883 ms
145,880 KB
testcase_12 AC 929 ms
145,932 KB
testcase_13 AC 934 ms
145,936 KB
testcase_14 AC 1,718 ms
145,876 KB
testcase_15 AC 1,758 ms
145,928 KB
testcase_16 AC 1,711 ms
145,880 KB
testcase_17 AC 1,784 ms
145,936 KB
testcase_18 AC 1,751 ms
145,880 KB
testcase_19 AC 1,729 ms
145,960 KB
testcase_20 AC 1,745 ms
145,900 KB
testcase_21 AC 1,785 ms
146,036 KB
testcase_22 AC 1,730 ms
145,928 KB
testcase_23 AC 1,792 ms
145,996 KB
testcase_24 AC 1,862 ms
145,972 KB
testcase_25 AC 1,866 ms
146,036 KB
testcase_26 AC 1,864 ms
145,944 KB
testcase_27 AC 1,860 ms
146,084 KB
testcase_28 AC 1,862 ms
145,976 KB
testcase_29 AC 438 ms
145,956 KB
testcase_30 AC 439 ms
145,952 KB
testcase_31 AC 434 ms
145,920 KB
testcase_32 AC 439 ms
145,884 KB
testcase_33 AC 439 ms
145,916 KB
testcase_34 AC 1,866 ms
145,884 KB
testcase_35 AC 39 ms
145,868 KB
testcase_36 AC 39 ms
145,844 KB
testcase_37 AC 39 ms
145,768 KB
testcase_38 AC 38 ms
145,832 KB
testcase_39 AC 38 ms
145,848 KB
testcase_40 AC 38 ms
145,832 KB
testcase_41 AC 38 ms
145,768 KB
testcase_42 AC 39 ms
145,796 KB
testcase_43 AC 437 ms
145,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
using mint=modint998244353;
mint dp[27][27][50005];
int main()
{
    int n; cin>>n;
    string s; cin>>s;
    dp[26][26][0]=1;
    for(int i=0; i<n; i++){
        for(int j=0; j<26; j++){
            if(s[i]!='?' && s[i]!=(char)('a'+j)) continue;
            for(int k=0; k<27; k++){
                if(k==j) continue;
                for(int l=0; l<27; l++){
                    if(l==j) continue;
                    dp[j][k][i+1]+=dp[k][l][i];
                }
            }
        }
    }
    mint ans=0;
    for(int i=0; i<27; i++){
        for(int j=0; j<27; j++){
            ans+=dp[i][j][n];
        }
    }
    cout<<ans.val()<<endl;
    return 0;
}
0