結果

問題 No.2254 Reverse Only
ユーザー KKT89KKT89
提出日時 2023-03-25 01:42:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 2,159 bytes
コンパイル時間 3,454 ms
コンパイル使用メモリ 221,564 KB
実行使用メモリ 19,244 KB
最終ジャッジ日時 2023-10-18 21:53:13
合計ジャッジ時間 7,241 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 74 ms
8,052 KB
testcase_09 AC 89 ms
19,244 KB
testcase_10 AC 43 ms
6,468 KB
testcase_11 AC 73 ms
8,052 KB
testcase_12 AC 74 ms
8,052 KB
testcase_13 AC 43 ms
6,468 KB
testcase_14 AC 74 ms
8,052 KB
testcase_15 AC 75 ms
8,052 KB
testcase_16 AC 88 ms
19,244 KB
testcase_17 AC 88 ms
19,244 KB
testcase_18 AC 74 ms
8,052 KB
testcase_19 AC 60 ms
8,052 KB
testcase_20 AC 74 ms
19,244 KB
testcase_21 AC 74 ms
19,244 KB
testcase_22 AC 47 ms
19,244 KB
testcase_23 AC 62 ms
19,244 KB
testcase_24 AC 59 ms
19,244 KB
testcase_25 AC 62 ms
19,244 KB
testcase_26 AC 63 ms
19,244 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 16 ms
4,356 KB
testcase_29 AC 34 ms
5,412 KB
testcase_30 AC 30 ms
5,148 KB
testcase_31 AC 17 ms
4,360 KB
testcase_32 AC 20 ms
4,620 KB
testcase_33 AC 10 ms
4,348 KB
testcase_34 AC 44 ms
6,204 KB
testcase_35 AC 29 ms
5,148 KB
testcase_36 AC 62 ms
7,260 KB
testcase_37 AC 65 ms
7,524 KB
testcase_38 AC 14 ms
4,348 KB
testcase_39 AC 58 ms
6,996 KB
testcase_40 AC 4 ms
4,348 KB
testcase_41 AC 26 ms
4,884 KB
testcase_42 AC 15 ms
4,356 KB
testcase_43 AC 47 ms
6,204 KB
testcase_44 AC 69 ms
7,788 KB
testcase_45 AC 42 ms
5,940 KB
testcase_46 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

vector<int> Zalgo(vector<int> s){
    int n=s.size();
    vector<int> a(n,0);
    int from=-1,last=-1;
    for(int i=1;i<n;i++){
        int &same=a[i];
        if(from!=-1){
            same=min(a[i-from],last-i);
            same=max(0,same);
        }
        while(i+same<n&&s[same]==s[i+same]){
            same++;
        }
        if(last<i+same){
            last=i+same;
            from=i;
        }
    }
    a[0]=n;
    return a;
}

bool slv(vector<int> a,vector<int> b,int n,int k) {
    if (a == b) {
        return true;
    }
    {
        auto v = a;
        auto vv = b;
        sort(v.begin(), v.end());
        sort(vv.begin(), vv.end());
        if (v != vv) return false;
    }
    if (k > n) {
        return false;
    }
    else if (k == n) {
        reverse(a.begin(), a.end());
        return (a == b);
    }
    else if (k < n-1) {
        return true;
    }
    else {
        // k = n-1
        vector<int> v;
        for (int i = 0; i < n; ++i) {
            v.push_back(b[i]);
        }
        v.push_back(-1);
        for (int i = 0; i < n; ++i) {
            v.push_back(a[i]);
        }
        for (int i = 0; i < n; ++i) {
            v.push_back(a[i]);
        }
        v.push_back(-1);
        for (int i = 0; i < n; ++i) {
            v.push_back(a[n-1-i]);
        }
        for (int i = 0; i < n; ++i) {
            v.push_back(a[n-1-i]);
        }
        auto Z = Zalgo(v);
        for (int i = n; i < v.size(); ++i) {
            if (Z[i] >= n) return true;
        }
        return false;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,k; cin >> n >> k;
    vector<int> a(n),b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    if (slv(a,b,n,k)) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}
0