結果

問題 No.1695 Mirror Mirror
ユーザー yakkiyakki
提出日時 2021-10-02 00:19:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,557 bytes
コンパイル時間 1,405 ms
コンパイル使用メモリ 126,764 KB
実行使用メモリ 62,296 KB
最終ジャッジ日時 2023-09-27 00:31:31
合計ジャッジ時間 6,102 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,760 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 15 ms
4,376 KB
testcase_05 WA -
testcase_06 TLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
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<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<ctime>
//#include<atcoder/all>
using namespace std;
//using namespace atcoder;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0)

const double EPS = 1e-18;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
//using mint = modint998244353;

int dh[] = {-1,1,0,0};
int dw[] = {0,0,1,-1};



int main(){
    int n,m; cin >> n >> m;
    string s,t; cin >> s >> t;
    if(m%2!=0){
        cout << -1 << endl;
        return 0;
    }
    string a = t.substr(0,m/2);
    string b = t.substr(m/2,m/2);
    reverse(b.begin(),b.end());
    if(a != b){
        cout << -1 << endl;
        return 0;
    }
    reverse(b.begin(),b.end());
    vector<string> v = {a,b};
    reverse(s.begin(),s.end());
    string ss = s;
    reverse(s.begin(),s.end());
    int cnt = 1;
    int ans = -1;
    while(1){
        for(auto p : v){
            if(p.size() > s.size()) continue;
            int k = p.size();
            bool ok = true;
            rep(i,k){
                if(s[i] != p[i]) ok = false;
            }
            if(ok){
                ans = cnt;
                break;
            }
            ok = true;
            rep(i,k){
                if(ss[i] != p[i]) ok = false;
            }
            if(ok){
                ans = cnt;
                break;
            }

        }
        vector<string> nxt;
        for(auto p : v){
            //cout << p << endl;
            int k = p.size();
            for(int i = 1; i < k; i++){
                string a2 = p.substr(0,i);
                string b2 = p.substr(i,k-i);
                reverse(a2.begin(),a2.end());
                if(a2.size()*2 < k) continue;
                bool ok = true;
                rep(j,b2.size()) if(a2[j] != b2[j]) ok = false;
                if(ok){
                    nxt.push_back(a2);
                    reverse(a2.begin(),a2.end());
                    nxt.push_back(a2);
                    break;
                }
            }
        }
        swap(v,nxt);
        cnt++;
        if(v.size() == 0) break;
    }
    cout << ans << endl;
}
0