結果

問題 No.2254 Reverse Only
ユーザー 0214sh7
提出日時 2023-03-24 22:48:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,783 bytes
コンパイル時間 1,736 ms
コンパイル使用メモリ 197,900 KB
最終ジャッジ日時 2025-02-11 17:36:03
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38 WA * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
//#define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false




int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    
    ll N,K;
    cin >> N >> K;
    vector<ll> A(N),B(N);
    REP(i,N){cin >> A[i];}
    REP(i,N){cin >> B[i];}
    vector<ll> rB = B;reverse(ALL(rB));
    
    if(K<=N-2){
        cout << "Yes" << endl;
        return 0;
    }
    
    if(K==N){
        if(A==B || A==rB){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
        return 0;
    }
    
    ll k = -1;
    REP(i,N){
        if(A[i]==B[0]){
            k = i;
        }
    }
    
    vector<ll> cA = A;
    REP(i,N){
        cA[i] = A[(i+k)%N];
    }
    
    if(cA == B){
        cout << "Yes" << endl;
        return 0;
    }
    
    
    k = -1;
    REP(i,N){
        if(A[i]==rB[0]){
            k = i;
        }
    }
    
    REP(i,N){
        cA[i] = A[(i+k)%N];
    }
    if(cA == rB){
        cout << "Yes" << endl;
        return 0;
    }
    
    cout << "No" << endl;
    
    /*ll N = 5,K = 3;
    cin >> N >> K;
    map<vector<ll>,ll> ind;
    ll now = 0;
    vector<ll> d(N);
    REP(i,N){d[i] = i;}

    do{
        
        ind[d] = now;
        now++;
        
    }while(next_permutation(ALL(d)));
    
    queue<vector<ll>> que;
    vector<bool> enqueued(now,false);
    
    REP(i,N){d[i] = i;}
    que.push(d);
    enqueued[ind[d]] = true;
    
    while(!que.empty()){
        
        vector<ll> t = que.front();
        que.pop();
        
        for(ll l=0;l<N;l++){
            for(ll r=l;r<N;r++){
                
                if((r-l+1)<K)continue;
                vector<ll> R = t;
                for(ll e=l;e<=r;e++){
                    R[e] = t[l+r-e];
                }
                
                if(!enqueued[ind[R]]){
                    que.push(R);
                    enqueued[ind[R]] = true;
                }
                
            }
        }
        
    }
    
    
    REP(i,N){d[i] = i;}
    ll c = 0;
    do{
        if(enqueued[ind[d]]){
            REP(i,N){
                cout << d[i] << " ";
            }
            cout << endl;
            c++;
        }
    }while(next_permutation(ALL(d)));
    
    cout << c MM (now-c) << endl;*/
    
    return 0;
}
0