結果

問題 No.2254 Reverse Only
ユーザー CoCo_Japan_panCoCo_Japan_pan
提出日時 2023-03-25 13:56:13
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,284 bytes
コンパイル時間 2,212 ms
コンパイル使用メモリ 208,488 KB
実行使用メモリ 6,316 KB
最終ジャッジ日時 2023-10-19 00:50:27
合計ジャッジ時間 6,219 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 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 75 ms
6,316 KB
testcase_09 AC 91 ms
6,316 KB
testcase_10 AC 49 ms
6,316 KB
testcase_11 AC 75 ms
6,316 KB
testcase_12 AC 74 ms
6,316 KB
testcase_13 AC 75 ms
6,316 KB
testcase_14 AC 75 ms
6,316 KB
testcase_15 AC 76 ms
6,316 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 75 ms
6,316 KB
testcase_19 AC 60 ms
6,316 KB
testcase_20 AC 71 ms
6,316 KB
testcase_21 AC 70 ms
6,316 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 3 ms
4,348 KB
testcase_28 AC 17 ms
4,348 KB
testcase_29 AC 35 ms
4,732 KB
testcase_30 AC 31 ms
4,468 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
4,996 KB
testcase_35 AC 29 ms
4,468 KB
testcase_36 AC 63 ms
5,788 KB
testcase_37 AC 66 ms
6,052 KB
testcase_38 AC 15 ms
4,348 KB
testcase_39 AC 59 ms
5,524 KB
testcase_40 AC 3 ms
4,348 KB
testcase_41 AC 27 ms
4,348 KB
testcase_42 AC 15 ms
4,348 KB
testcase_43 AC 49 ms
5,260 KB
testcase_44 AC 71 ms
6,052 KB
testcase_45 AC 43 ms
4,996 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 isTotallySame(const vec<int> &A, const vec<int> &B) {
    if(A.size() != B.size()) return false;
    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) {
        return isTotallySame(A, B);
    }
    if(k == N) {
        vec<int> rev_A = A;
        reverse(ALL(rev_A));
        return (isTotallySame(A, B) || isTotallySame(rev_A, B));
    }
    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