結果

問題 No.2254 Reverse Only
ユーザー 👑 NachiaNachia
提出日時 2023-03-23 05:44:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 1,939 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 101,636 KB
実行使用メモリ 12,736 KB
最終ジャッジ日時 2023-10-18 19:20:56
合計ジャッジ時間 10,614 ms
ジャッジサーバーID
(参考情報)
judge13 / 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 72 ms
6,400 KB
testcase_09 AC 270 ms
12,736 KB
testcase_10 AC 46 ms
6,400 KB
testcase_11 AC 73 ms
6,400 KB
testcase_12 AC 73 ms
6,400 KB
testcase_13 AC 73 ms
6,400 KB
testcase_14 AC 72 ms
6,400 KB
testcase_15 AC 73 ms
6,400 KB
testcase_16 AC 276 ms
12,736 KB
testcase_17 AC 273 ms
12,736 KB
testcase_18 AC 72 ms
6,400 KB
testcase_19 AC 58 ms
6,400 KB
testcase_20 AC 259 ms
12,736 KB
testcase_21 AC 260 ms
12,736 KB
testcase_22 AC 255 ms
12,736 KB
testcase_23 AC 256 ms
12,736 KB
testcase_24 AC 270 ms
12,736 KB
testcase_25 AC 268 ms
12,736 KB
testcase_26 AC 270 ms
12,736 KB
testcase_27 AC 4 ms
4,348 KB
testcase_28 AC 16 ms
4,348 KB
testcase_29 AC 34 ms
4,816 KB
testcase_30 AC 30 ms
4,552 KB
testcase_31 AC 17 ms
4,348 KB
testcase_32 AC 19 ms
4,348 KB
testcase_33 AC 10 ms
4,348 KB
testcase_34 AC 43 ms
5,080 KB
testcase_35 AC 29 ms
4,552 KB
testcase_36 AC 61 ms
5,872 KB
testcase_37 AC 69 ms
6,136 KB
testcase_38 AC 14 ms
4,348 KB
testcase_39 AC 57 ms
5,608 KB
testcase_40 AC 4 ms
4,348 KB
testcase_41 AC 25 ms
4,348 KB
testcase_42 AC 15 ms
4,348 KB
testcase_43 AC 47 ms
5,344 KB
testcase_44 AC 68 ms
6,136 KB
testcase_45 AC 43 ms
5,080 KB
testcase_46 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>
#include <atcoder/string>
using namespace std;
using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
const i64 INF = 1001001001001001001;

using Modint = atcoder::static_modint<998244353>;

int main(){
    int N; cin >> N;
    int K; cin >> K;
    vector<int> A(N); rep(i,N) cin >> A[i];
    vector<int> B(N); rep(i,N) cin >> B[i];
    vector<int> sA = A; sort(sA.begin(), sA.end());
    vector<int> sB = B; sort(sB.begin(), sB.end());
    bool ans = false;
    if(K > N){
        ans = (A == B);
    }
    else if(sA != sB){
        ans = false;
    }
    else if(K == N){
        rep(t,2){
            if(A == B) ans = true;
            reverse(A.begin(), A.end());
        }
    }
    else if(K <= N-2){
        ans = true;
    }
    else{
        auto judge = [&ans](vector<int> A, vector<int> B){
            int n = A.size();
            vector<int> BAA(n*3);
            rep(i,n) BAA[n+i] = BAA[n+n+i] = A[i];
            rep(i,n) BAA[i] = B[i];
            auto Z = atcoder::z_algorithm(BAA);
            if(n % 2 == 1){
                for(int i=n; i<2*n; i++) if(Z[i] >= n) ans = true;
            } else {
                for(int i=n; i<2*n; i+=2) if(Z[i] >= n) ans = true;
            }
        };
        rep(y,2){
            rep(u,2) rep(v,2){
                rep(s,2) rep(t,2){
                    judge(A, B);
                    reverse(A.begin() + s, A.begin() + (N-1+s));
                }
                reverse(B.begin() + u, B.begin() + (N-1+u));
            }
            reverse(A.begin(), A.end());
        }
    }

    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}



struct ios_do_not_sync{
    ios_do_not_sync(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;

0