結果

問題 No.2254 Reverse Only
ユーザー lddlinanlddlinan
提出日時 2023-03-25 14:18:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,598 bytes
コンパイル時間 878 ms
コンパイル使用メモリ 94,516 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2023-10-19 01:06:01
合計ジャッジ時間 8,611 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,288 KB
testcase_01 AC 3 ms
7,288 KB
testcase_02 AC 2 ms
7,288 KB
testcase_03 AC 3 ms
7,288 KB
testcase_04 AC 2 ms
7,288 KB
testcase_05 AC 3 ms
7,288 KB
testcase_06 AC 2 ms
7,288 KB
testcase_07 AC 2 ms
7,288 KB
testcase_08 AC 246 ms
13,208 KB
testcase_09 AC 247 ms
13,880 KB
testcase_10 AC 50 ms
7,288 KB
testcase_11 AC 250 ms
13,208 KB
testcase_12 AC 138 ms
13,216 KB
testcase_13 AC 237 ms
13,200 KB
testcase_14 AC 241 ms
13,224 KB
testcase_15 AC 242 ms
13,212 KB
testcase_16 AC 243 ms
13,884 KB
testcase_17 AC 238 ms
13,884 KB
testcase_18 AC 219 ms
13,232 KB
testcase_19 AC 72 ms
7,296 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 7 ms
7,556 KB
testcase_28 AC 39 ms
9,096 KB
testcase_29 AC 102 ms
10,752 KB
testcase_30 AC 80 ms
10,396 KB
testcase_31 AC 41 ms
9,200 KB
testcase_32 AC 48 ms
9,428 KB
testcase_33 AC 20 ms
8,344 KB
testcase_34 AC 133 ms
11,484 KB
testcase_35 AC 80 ms
10,264 KB
testcase_36 AC 207 ms
12,644 KB
testcase_37 AC 212 ms
12,796 KB
testcase_38 AC 31 ms
8,824 KB
testcase_39 AC 177 ms
12,384 KB
testcase_40 AC 6 ms
7,552 KB
testcase_41 AC 72 ms
10,024 KB
testcase_42 AC 35 ms
8,956 KB
testcase_43 AC 143 ms
11,716 KB
testcase_44 AC 229 ms
13,000 KB
testcase_45 AC 126 ms
11,404 KB
testcase_46 AC 6 ms
7,504 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[600004];
int zf[400004];
int main() {
    int n, i, k, v, t, s, e;
    int c, ze, zc, pe, pi, pc;
    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) {
            for (i=0; i<n; i++) bs[i+n]=bs[i+n+n]=as[i];
            e=-1; c=0;
            zf[0]=0;
            for (i=1; i<n+n; i++) {
                if (e<i) { ze=i; zc=0; }
                else {
                    // [e-c, e)
                    s=e-c; pi=i-s; pe=zf[pi]; pc=pe-pi;
                    ze=i+pc; if (ze>e) ze=e;
                    zc=ze-pi;
                }
                while(ze<n+n+n&&bs[ze]==bs[c]) { ze++; c++; }
                if (i>=n&&c>=n) break;
                if (ze>e) { e=ze; c=zc; }
                zf[i]=ze;
            }
            if (i<n+n) { printf("Yes\n"); return 0; }
            s=0; e=n-1; while(s<e) {
                t=bs[s]; bs[s]=bs[e]; bs[e]=t;
                s++; e--;
            }
            e=-1; c=0;
            for (i=1; i<n+n; i++) {
                if (e<i) { ze=i; zc=0; }
                else {
                    // [e-c, e)
                    s=e-c; pi=i-s; pe=zf[pi]; pc=pe-pi;
                    ze=i+pc; if (ze>e) ze=e;
                    zc=ze-pi;
                }
                while(ze<n+n+n&&bs[ze]==bs[c]) { ze++; c++; }
                if (i>=n&&c>=n) break;
                if (ze>e) { e=ze; c=zc; }
                zf[i]=ze;
            }
            if (i<n+n) { printf("Yes\n"); return 0; }
            printf("No\n");
            return 0;
        }
        printf("Yes\n");
    }
    return 0;
}
0