結果

問題 No.1695 Mirror Mirror
ユーザー eSeFeSeF
提出日時 2021-08-10 05:37:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,255 bytes
コンパイル時間 4,544 ms
コンパイル使用メモリ 264,076 KB
実行使用メモリ 9,804 KB
最終ジャッジ日時 2023-09-26 15:40:05
合計ジャッジ時間 8,967 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,756 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 22 ms
5,872 KB
testcase_22 TLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
testcase_58 -- -
testcase_59 -- -
testcase_60 -- -
testcase_61 -- -
testcase_62 -- -
testcase_63 -- -
testcase_64 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main(){
    int N, M;
    cin >> N >> M;
    string S, T;
    cin >> S;
    cin >> T;

    if(M%2==1){cout << -1 << endl;return 0;}
    for(int i=0;i<M/2;i++){
        if(T[i]!=T[M-1-i]){
            cout << -1 << endl;
            return 0;
        }
    }
    M/=2;
    T = T.substr(0,M);
    int INF = 1<<30;
    vector<int>dp(M,INF);
    for(int i=0;i<N;i++){
        if(i>=M||S[i]!=T[i])break;
        dp[i] = 1;
    }
    for(int i=0;i<N;i++){
        if(i>=M||S[N-1-i]!=T[i])break;
        dp[i] = 1;
    }

    //manacherしない
    int flag = 0;
    stack<int>st;
    for(int i=0;i<M;i++){
        if(dp[i]!=1)break;
        st.push(i);
    }
    while(st.size()){
        int i = st.top();
        st.pop();

        for(int j=0;i-j>=0&&i+1+j<M;j++){
            if(T[i-j]!=T[i+1+j])break;
            dp[i+j+1]=min(dp[i+j+1],dp[i]+1);

            if(dp[M-1]!=INF){
                flag = 1;
                break;
            }
            st.push(i+j+1);
        }
        if(flag)break;
    }
    if(dp[M-1]==INF){
        cout << -1 << endl;
    }
    else{
        cout << dp[M-1] << endl;
    }
    

    return 0;
}
0