結果

問題 No.1695 Mirror Mirror
ユーザー eSeFeSeF
提出日時 2021-08-10 05:21:33
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,453 bytes
コンパイル時間 3,931 ms
コンパイル使用メモリ 152,696 KB
実行使用メモリ 5,212 KB
最終ジャッジ日時 2023-09-26 15:39:40
合計ジャッジ時間 9,513 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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;
    }

    //貪欲に伸ばす
    int itr = -1;
    for(int i=M-1;i>=0;i--){
        if(dp[i] == 1){
            itr = i;
            break;
        }
    }
    if(itr == -1){
        cout << -1 << endl;
        return 0;
    }
    //cout << itr << endl;
    while (true)
    {
        int c = dp[itr];
        int nitr = -1;
        for(int i=0;itr+i+1<M;i++){
            if(S[itr-i] == S[itr+1 + i]){
                dp[itr + 1 + i] = c + 1;
                nitr = itr + 1 + i;
            }
            else{
                break;
            }
        }
        if(nitr==-1){
            cout << -1 << endl;
            return 0;
        }
        itr = nitr;
        //cout << "nitr = " << nitr << endl;
        if(itr == M - 1){
            break;
        }
    }
    cout << dp[M-1] << endl;
    


    return 0;
}
0