結果

問題 No.1646 Avoid Palindrome
ユーザー HIcoderHIcoder
提出日時 2023-07-22 18:13:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,840 bytes
コンパイル時間 2,916 ms
コンパイル使用メモリ 107,080 KB
実行使用メモリ 320,164 KB
最終ジャッジ日時 2023-10-24 00:46:14
合計ジャッジ時間 90,893 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2,569 ms
301,932 KB
testcase_05 AC 2,554 ms
301,940 KB
testcase_06 AC 2,465 ms
291,644 KB
testcase_07 AC 2,551 ms
301,940 KB
testcase_08 AC 2,576 ms
304,844 KB
testcase_09 AC 2,449 ms
289,796 KB
testcase_10 AC 2,505 ms
296,924 KB
testcase_11 AC 2,442 ms
288,740 KB
testcase_12 AC 2,550 ms
301,412 KB
testcase_13 AC 2,577 ms
304,844 KB
testcase_14 AC 2,884 ms
296,132 KB
testcase_15 AC 2,933 ms
301,940 KB
testcase_16 AC 2,864 ms
294,284 KB
testcase_17 AC 2,987 ms
307,220 KB
testcase_18 AC 2,904 ms
299,036 KB
testcase_19 AC 2,900 ms
297,452 KB
testcase_20 AC 2,915 ms
299,828 KB
testcase_21 AC 2,979 ms
306,956 KB
testcase_22 AC 2,879 ms
296,396 KB
testcase_23 AC 2,997 ms
308,548 KB
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 AC 2,405 ms
320,156 KB
testcase_30 AC 2,401 ms
320,156 KB
testcase_31 AC 2,401 ms
320,156 KB
testcase_32 AC 2,410 ms
320,156 KB
testcase_33 AC 2,409 ms
320,156 KB
testcase_34 TLE -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 2 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 2 ms
4,348 KB
testcase_41 AC 2 ms
4,348 KB
testcase_42 AC 2 ms
4,348 KB
testcase_43 AC 2,413 ms
320,156 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<numeric>
#include<queue>
#include<cmath>
#include<deque>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
const ll MOD=998244353;


int main(){
    int N;
    cin>>N;
    string S;
    cin>>S;

    /*
    dp[i][j][k]=i文字目がk, i-1文字目がj
    */

    vector dp(N+1,vector<vector<ll>>(26,vector<ll>(26,0)));

    for(int j=0;j<26;j++){

        if( S[0]-'a' == j || S[0]=='?' ){

            for(int k=0;k<26;k++){
                if( (S[1]-'a'==k || S[1]=='?') && k!=j ){

                    dp[1][j][k]=1;
                }
            }
        }
    }

    for(int i=2;i<N;i++){

        for(int j=0;j<26;j++){
            for(int k=0;k<26;k++){

                if(j==k) continue;

                for(int l=0;l<26;l++){
                    //直前の文字列は順番に, j,k,l となっている. i文字目がl文字目
                    if(l==k || l==j) continue;

                    if(S[i]-'a'==l || S[i]=='?'){
                    

                        dp[i][k][l]+=dp[i-1][j][k];
                        dp[i][k][l]%=MOD;
                    }

                }



            }
        }

    }

    ll ans=0;

    for(int j=0;j<26;j++){
        for(int k=0;k<26;k++){
            if(j==k) continue;
            ans+=dp[N-1][j][k];
            ans%=MOD;
        }
    }
    cout<<ans<<endl;


    /*
    for(int i=0;i<26;i++){
        for(int j=0;j<26;j++){
            if(i!=j){
                dp[0][i][j]=1;
            }
        }
    }

    S=S+ (S.back()-'a'+1)%26
    


    for(int i=0;i<N;i++){
        if(S[i]!='?'){

            for(int j=0;j<26;j++){
                for(int k=0;k<26;k++){
                    if(j==k) continue;

                    if(k==(S[i]-'a'))continue;  //k==S[i]となるとまずい
                    if(j==(S[i]-'a'))continue;  //j==S[i]となるとまずい

            
                    dp[i+1][k][S[i]-'a']+=dp[i][j][k];
                
                }
            }

        }else{
            //S[i]=='?'

            for(int j=0;j<26;j++){
                for(int k=0;k<26;k++){

                    for(int l=0;l<26;l++){
                        if(j==k) continue;
                        if(j==l) continue;
                        if(k==l) continue;
                    

                        dp[i+1][k][l]+=dp[i][j][k];

                    }

                }
            }


        }
    }

    for(int j=0;j<26;j++){
        for(int k=0;k<26;k++){
        cout<<"dp["<<j<<"]["<<k<<"]="<<dp[N][j][k]<<endl;
        }
    }

    if(N>=2){
        ll ans=dp[N][S[S.size()-2]-'a'][S[S.size()-1]-'a'];
        cout<<ans<<endl;
    }
    */
}
0