結果

問題 No.2254 Reverse Only
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-03-25 13:53:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,202 bytes
コンパイル時間 2,274 ms
コンパイル使用メモリ 208,288 KB
実行使用メモリ 6,408 KB
最終ジャッジ日時 2023-10-19 00:47:32
合計ジャッジ時間 6,778 ms
ジャッジサーバーID
(参考情報)
judge15 / 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 76 ms
6,408 KB
testcase_09 AC 93 ms
6,408 KB
testcase_10 AC 49 ms
6,408 KB
testcase_11 AC 75 ms
6,408 KB
testcase_12 AC 75 ms
6,408 KB
testcase_13 AC 76 ms
6,408 KB
testcase_14 AC 76 ms
6,408 KB
testcase_15 AC 77 ms
6,408 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 76 ms
6,408 KB
testcase_19 AC 62 ms
6,408 KB
testcase_20 AC 71 ms
6,408 KB
testcase_21 AC 71 ms
6,408 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 17 ms
4,348 KB
testcase_29 AC 35 ms
4,824 KB
testcase_30 AC 31 ms
4,560 KB
testcase_31 AC 18 ms
4,348 KB
testcase_32 AC 20 ms
4,348 KB
testcase_33 AC 10 ms
4,348 KB
testcase_34 AC 45 ms
5,088 KB
testcase_35 AC 29 ms
4,560 KB
testcase_36 AC 63 ms
5,880 KB
testcase_37 AC 67 ms
6,144 KB
testcase_38 AC 14 ms
4,348 KB
testcase_39 AC 59 ms
5,616 KB
testcase_40 AC 4 ms
4,348 KB
testcase_41 AC 26 ms
4,348 KB
testcase_42 AC 16 ms
4,348 KB
testcase_43 AC 48 ms
5,352 KB
testcase_44 AC 71 ms
6,144 KB
testcase_45 AC 43 ms
5,088 KB
testcase_46 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 提出時にassertはオフ
#ifndef DEBUG
#ifndef NDEBUG
#define NDEBUG
#endif
#endif

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define ALL(x) (x).begin(), (x).end()
template <class T> using vec = vector<T>;

int N, k;

// 多重集合一致判定
bool isSameSet(const vec<int> &A_, const vec<int> &B_) {
    vec<int> A = A_, B = B_;
    if(A.size() != B.size()) {
        return false;
    }
    sort(ALL(A));
    sort(ALL(B));
    for(int i = 0; i < (int)A.size(); i++) {
        if(A[i] != B[i]) return false;
    }
    return true;
}

bool solve(const vec<int> &A, const vec<int> &B) {
    if(!isSameSet(A, B)) return false;
    int size = A.size();
    if(k > N) {
        for(int i = 0; i < size; i++){
            if(A[i] != B[i]) return false;
        }
        return true;
    }
    if(k == N) {
        vec<int> rev_A = A;
        reverse(ALL(rev_A));
        for(int i = 0; i < size; i++) {
            if(rev_A[i] != B[i]) return false;
        }
        return true;
    }
    if(k == N - 1) {
        vec<int> sorted_A = A;
        sort(ALL(sorted_A));
        int startIndex = -1;
        for(int i = 0; i < size; i++) {
            if(B[i] == sorted_A[0]) {
                startIndex = i;
                break;
            }
        }
        int nextIndex = (startIndex + 1) % size;
        int prevIndex = (startIndex + size - 1) % size; 
        if(B[nextIndex] == sorted_A[1]) {
            for(int i = 0; i < size; i++) {
                if(B[(startIndex + i) % size] != sorted_A[i]) {
                    return false;
                }
                return true;
            }
        }
        if(B[prevIndex] == sorted_A[1]) {
            for(int i = 0; i < size; i++) {
                if(B[(startIndex + size - i) % size] != sorted_A[i]) {
                    return false;
                }
                return true;
            }
        }
        return false;
    }
    // k <= N - 2
    return true;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> k;
    vec<int> A(N), B(N);
    for(int &a : A) cin >> a;
    for(int &b : B) cin >> b;
    cout << (solve(A, B) ? "Yes" : "No") << "\n";
}
0