結果

問題 No.2254 Reverse Only
ユーザー noya2noya2
提出日時 2023-03-13 15:03:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 1,115 bytes
コンパイル時間 3,089 ms
コンパイル使用メモリ 225,576 KB
実行使用メモリ 14,152 KB
最終ジャッジ日時 2023-10-18 11:06:26
合計ジャッジ時間 11,604 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 154 ms
6,496 KB
testcase_09 AC 133 ms
14,152 KB
testcase_10 AC 126 ms
4,912 KB
testcase_11 AC 153 ms
6,496 KB
testcase_12 AC 153 ms
6,496 KB
testcase_13 AC 119 ms
4,912 KB
testcase_14 AC 119 ms
4,912 KB
testcase_15 AC 119 ms
4,912 KB
testcase_16 AC 133 ms
14,152 KB
testcase_17 AC 133 ms
14,152 KB
testcase_18 AC 152 ms
6,496 KB
testcase_19 AC 146 ms
6,496 KB
testcase_20 AC 139 ms
14,152 KB
testcase_21 AC 139 ms
14,152 KB
testcase_22 AC 77 ms
14,152 KB
testcase_23 AC 141 ms
14,152 KB
testcase_24 AC 129 ms
14,152 KB
testcase_25 AC 142 ms
14,152 KB
testcase_26 AC 141 ms
14,152 KB
testcase_27 AC 5 ms
4,348 KB
testcase_28 AC 33 ms
4,348 KB
testcase_29 AC 56 ms
4,348 KB
testcase_30 AC 62 ms
4,648 KB
testcase_31 AC 28 ms
4,348 KB
testcase_32 AC 32 ms
4,348 KB
testcase_33 AC 16 ms
4,348 KB
testcase_34 AC 71 ms
4,384 KB
testcase_35 AC 47 ms
4,348 KB
testcase_36 AC 130 ms
5,968 KB
testcase_37 AC 135 ms
6,232 KB
testcase_38 AC 23 ms
4,348 KB
testcase_39 AC 120 ms
5,704 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 42 ms
4,348 KB
testcase_42 AC 25 ms
4,348 KB
testcase_43 AC 77 ms
4,384 KB
testcase_44 AC 112 ms
4,912 KB
testcase_45 AC 89 ms
5,176 KB
testcase_46 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/string>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
void yes(){ printf("Yes\n"); }
void no(){ printf("No\n"); }

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(j,n) cin >> b[j];
    if (a == b){
        yes();
    }
    else if (k > n){
        no();
    }
    else if (k == n){
        reverse(all(b));
        a == b ? yes() : no();
    }
    else if (k == n-1){
        vector<int> c(3*n), d(3*n);
        rep(i,n){
            c[i] = a[i], d[i] = a[i];
            c[n+i] = b[i], d[n+i] = b[n-1-i];
            c[2*n+i] = b[i], d[2*n+i] = b[n-1-i];
        }
        auto zc = atcoder::z_algorithm(c);
        auto zd = atcoder::z_algorithm(d);
        bool ans = false;
        rep(i,n){
            if (zc[n+i] >= n) ans = true;
            if (zd[n+i] >= n) ans = true;
        }
        ans ? yes() : no();
    }
    else {
        vector<int> sa = a; sort(all(sa));
        vector<int> sb = b; sort(all(sb));
        sa == sb ? yes(): no();
    }
}
0