結果

問題 No.2254 Reverse Only
ユーザー HaaHaa
提出日時 2023-03-24 22:25:01
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,909 bytes
コンパイル時間 1,923 ms
コンパイル使用メモリ 177,236 KB
実行使用メモリ 25,296 KB
最終ジャッジ日時 2023-10-18 21:15:34
合計ジャッジ時間 7,328 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 2 ms
4,368 KB
testcase_08 AC 149 ms
6,528 KB
testcase_09 AC 135 ms
25,296 KB
testcase_10 AC 125 ms
6,528 KB
testcase_11 AC 149 ms
6,528 KB
testcase_12 AC 149 ms
6,528 KB
testcase_13 AC 118 ms
6,528 KB
testcase_14 AC 117 ms
6,528 KB
testcase_15 AC 117 ms
6,528 KB
testcase_16 AC 129 ms
20,676 KB
testcase_17 AC 129 ms
20,668 KB
testcase_18 AC 149 ms
6,528 KB
testcase_19 AC 144 ms
6,528 KB
testcase_20 AC 142 ms
25,296 KB
testcase_21 AC 142 ms
25,296 KB
testcase_22 AC 81 ms
25,296 KB
testcase_23 AC 143 ms
25,296 KB
testcase_24 AC 123 ms
20,676 KB
testcase_25 AC 135 ms
20,676 KB
testcase_26 AC 136 ms
20,676 KB
testcase_27 AC 5 ms
4,368 KB
testcase_28 AC 33 ms
4,368 KB
testcase_29 AC 55 ms
4,944 KB
testcase_30 AC 60 ms
4,680 KB
testcase_31 AC 28 ms
4,368 KB
testcase_32 AC 32 ms
4,368 KB
testcase_33 AC 16 ms
4,368 KB
testcase_34 AC 71 ms
5,208 KB
testcase_35 AC 46 ms
4,680 KB
testcase_36 AC 126 ms
6,000 KB
testcase_37 AC 132 ms
6,000 KB
testcase_38 AC 23 ms
4,368 KB
testcase_39 AC 118 ms
5,736 KB
testcase_40 AC 5 ms
4,368 KB
testcase_41 AC 42 ms
4,416 KB
testcase_42 AC 25 ms
4,368 KB
testcase_43 AC 75 ms
5,472 KB
testcase_44 AC 110 ms
6,264 KB
testcase_45 AC 87 ms
5,208 KB
testcase_46 AC 5 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

VI zalgo(VI s){
    int n=s.size();
    VI z(n); z[0]=n;
    int i=1, j=0;
    while(i<n){
        while(i+j<n&&s[j]==s[i+j]) j++;
        z[i]=j;
        if(j==0){
            i++;
            continue;
        }
        int k=1;
        while(k<j&&k+z[k]<j){
            z[i+k]=z[k];
            k++;
        }
        i+=k;
        j-=k;
    }
    return z;
}

int main(){
    int n, k; cin >> n >> k;
    VI a(n), b(n);
    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];
    if(k<n-1){
        sort(ALL(a));
        sort(ALL(b));
        if(a==b)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    else if(k==n-1){
        VI c, z;
        c=a;
        REP(i,n*2) c.push_back(b[i%n]);
        z=zalgo(c);
        REP(i,n){
            if(z[i+n]>=n){
                cout << "Yes" << endl;
                return 0;
            }
        }
        reverse(ALL(a));
        c=a;
        REP(i,n*2) c.push_back(b[i%n]);
        z=zalgo(c);
        REP(i,n){
            if(z[i+n]>=n){
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
    }
    else{
        if(a==b){
            cout << "Yes" << endl;
            return 0;
        }
        if(k>n){
            cout << "No" << endl;
            return 0;
        }
        reverse(ALL(a));
        if(a==b)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}
0