結果

問題 No.2254 Reverse Only
ユーザー lddlinanlddlinan
提出日時 2023-03-25 00:00:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,434 bytes
コンパイル時間 875 ms
コンパイル使用メモリ 94,532 KB
実行使用メモリ 10,600 KB
最終ジャッジ日時 2023-10-18 21:44:17
合計ジャッジ時間 7,792 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,348 KB
testcase_08 AC 216 ms
10,576 KB
testcase_09 AC 210 ms
10,580 KB
testcase_10 AC 50 ms
4,656 KB
testcase_11 AC 219 ms
10,576 KB
testcase_12 AC 127 ms
10,584 KB
testcase_13 AC 214 ms
10,568 KB
testcase_14 AC 227 ms
10,592 KB
testcase_15 AC 215 ms
10,580 KB
testcase_16 AC 211 ms
10,584 KB
testcase_17 AC 215 ms
10,584 KB
testcase_18 AC 197 ms
10,600 KB
testcase_19 AC 71 ms
4,664 KB
testcase_20 AC 72 ms
4,664 KB
testcase_21 AC 72 ms
4,664 KB
testcase_22 AC 37 ms
4,656 KB
testcase_23 AC 50 ms
4,656 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 6 ms
4,348 KB
testcase_28 AC 37 ms
5,240 KB
testcase_29 AC 91 ms
7,284 KB
testcase_30 AC 75 ms
6,832 KB
testcase_31 AC 39 ms
5,364 KB
testcase_32 AC 45 ms
5,640 KB
testcase_33 AC 19 ms
4,348 KB
testcase_34 AC 120 ms
8,224 KB
testcase_35 AC 70 ms
6,668 KB
testcase_36 AC 172 ms
9,776 KB
testcase_37 AC 185 ms
9,984 KB
testcase_38 AC 31 ms
4,916 KB
testcase_39 AC 165 ms
9,420 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 63 ms
6,372 KB
testcase_42 AC 33 ms
5,072 KB
testcase_43 AC 127 ms
8,524 KB
testcase_44 AC 200 ms
10,276 KB
testcase_45 AC 118 ms
8,120 KB
testcase_46 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;
class mypcmp {
public:
    bool operator()(const int& a, const int& b) {
        return a<b;
    }
};



int as[200004];
int bs[200004];
int main() {
    int n, i, k, v, t, s, e;
    scanf("%d %d", &n, &k);
    for (i=0; i<n; i++) scanf("%d", &as[i]);
    for (i=0; i<n; i++) scanf("%d", &bs[i]);
    map<int, int> cs;
    for (i=0; i<n; i++) cs[as[i]]++;
    for (i=0; i<n; i++) {
        v=bs[i];
        if (cs[v]==0) break;
        cs[v]--;
    }
    if(i<n) printf("No\n");
    else {
        for (i=0; i<n; i++) if (as[i]!=bs[i]) break;
        if (i>=n) { printf("Yes\n"); return 0; }
        if (k>n) { printf("No\n"); return 0; }
        for (i=0; i<n; i++) if (as[i]!=bs[n-1-i]) break;
        if (i>=n) { printf("Yes\n"); return 0; }
        if (k==n) { printf("No\n"); return 0; }
        if (k==n-1) {
            if (as[0]==bs[0]) {
                for (i=1; i<n; i++) if (as[i]!=bs[n-i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
            }
            if (as[n-1]==bs[n-1]) {
                for (i=0; i<n-1; i++) if (as[i]!=bs[n-1-1-i]) break;
                if (i>=n-1) { printf("Yes\n"); return 0; }
            }
            if (as[0]==bs[1]) {
                s=1; e=n-1;
                while(s<e) {
                    t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                    s++; e--;
                }
                for (i=0; i<n; i++) if (as[i]!=bs[n-1-i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
            } else if (as[n-1]==bs[n-2]) {
                s=0; e=n-2;
                while(s<e) {
                    t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                    s++; e--;
                }
                for (i=0; i<n; i++) if (as[i]!=bs[n-1-i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
            } else if (as[0]==bs[n-2]) {
                s=0; e=n-2;
                while(s<e) {
                    t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                    s++; e--;
                }
                for (i=0; i<n; i++) if (as[i]!=bs[i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
                s=1; e=n-1;
                while(s<e) {
                    t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                    s++; e--;
                }
                for (i=0; i<n; i++) if (as[i]!=bs[i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
            } else if (as[n-1]==bs[1]) {
                s=1; e=n-1;
                while(s<e) {
                    t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                    s++; e--;
                }
                for (i=0; i<n; i++) if (as[i]!=bs[i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
                s=0; e=n-2;
                while(s<e) {
                    t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                    s++; e--;
                }
                for (i=0; i<n; i++) if (as[i]!=bs[i]) break;
                if (i>=n) { printf("Yes\n"); return 0; }
            }
            printf("No\n");
            return 0;
        }
        printf("Yes\n");
    }
    return 0;
}
0