結果

問題 No.2254 Reverse Only
ユーザー ThistleThistle
提出日時 2023-03-25 00:31:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 200 ms / 2,000 ms
コード長 5,435 bytes
コンパイル時間 1,480 ms
コンパイル使用メモリ 126,612 KB
実行使用メモリ 19,720 KB
最終ジャッジ日時 2023-10-18 21:50:16
合計ジャッジ時間 7,493 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,500 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 152 ms
4,916 KB
testcase_09 AC 200 ms
19,720 KB
testcase_10 AC 126 ms
4,916 KB
testcase_11 AC 153 ms
6,500 KB
testcase_12 AC 153 ms
6,500 KB
testcase_13 AC 120 ms
4,916 KB
testcase_14 AC 119 ms
4,916 KB
testcase_15 AC 120 ms
4,916 KB
testcase_16 AC 200 ms
19,720 KB
testcase_17 AC 199 ms
19,720 KB
testcase_18 AC 153 ms
4,916 KB
testcase_19 AC 147 ms
4,916 KB
testcase_20 AC 192 ms
19,720 KB
testcase_21 AC 192 ms
19,720 KB
testcase_22 AC 114 ms
19,720 KB
testcase_23 AC 181 ms
19,720 KB
testcase_24 AC 158 ms
19,720 KB
testcase_25 AC 169 ms
19,720 KB
testcase_26 AC 171 ms
19,720 KB
testcase_27 AC 5 ms
4,348 KB
testcase_28 AC 34 ms
4,348 KB
testcase_29 AC 56 ms
4,348 KB
testcase_30 AC 62 ms
4,348 KB
testcase_31 AC 29 ms
4,348 KB
testcase_32 AC 32 ms
4,348 KB
testcase_33 AC 16 ms
4,348 KB
testcase_34 AC 72 ms
4,388 KB
testcase_35 AC 47 ms
4,348 KB
testcase_36 AC 129 ms
4,652 KB
testcase_37 AC 135 ms
4,652 KB
testcase_38 AC 23 ms
4,348 KB
testcase_39 AC 120 ms
4,652 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 43 ms
4,348 KB
testcase_42 AC 25 ms
4,348 KB
testcase_43 AC 78 ms
4,388 KB
testcase_44 AC 112 ms
4,916 KB
testcase_45 AC 88 ms
4,348 KB
testcase_46 AC 4 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#pragma GCC target ("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<limits>
#include<complex>
#include<time.h>
#include<cassert>
#include<functional>
#include<numeric>
#include<tuple>
using namespace std;
using ll = long long;
using ld = long double;
using H = pair<ll, ll>;
using P = pair<ll, H>;
using vi = vector<int>;
using vl = vector<ll>;
#define all(a) (a).begin(),(a).end()
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define Q(i,j,k) mkp((i),mkp((j),(k)))
#define rng(i,s,n) for(int i = (s) ; i < (n) ; i++)
#define rep(i,n) rng(i, 0, (n))
#define mkp make_pair
#define vec vector
#define pb emplace_back
#define siz(a) int((a).size())
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define getidx(b,i) (lower_bound(all((b)),(i))-(b).begin())
#define ssp(i,n) (i==(ll)(n)-1?"\n":" ")
#define ctoi(c) (int)((c)-'0')
#define itoc(c) (char)((c)+'0')
#define cyes printf("Yes\n")
#define cno printf("No\n")
#define cdf(n) for(int __quetimes=(n);__quetimes>0;__quetimes--)
#define gcj printf("Case #%lld: ",__quetimes+1)
#define readv(a,n) (a).resize((n),0);rep(i,(n)) (a)[i]=read()
#define found(a,x) (a.find(x)!=a.end())
constexpr ll mod = (ll)1e9 + 7;
constexpr ll Mod = 998244353;
constexpr ld EPS = 1e-10;
constexpr ll inf = (ll)3 * 1e18;
constexpr int Inf = 1e9;
constexpr int dx[] = { -1,1,0,0 }, dy[] = { 0,0,-1,1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
ll read() { ll u, k = scanf("%lld", &u); return u; }
string reads() { string s; cin >> s; return s; }
bool ina(H t, int h, int w) { return 0 <= t.fs && t.fs < h && 0 <= t.sc && t.sc < w; }
bool ina(int t, int l, int r) { return l <= t && t < r; }
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
template<typename T>
void fin(T x) { cout << x << endl; exit(0); }
//--------------------------------------------------------------

class RH {
    static long long b1, b2;
    static long long m1, m2;
    vector<long long>h1, h2;
    static vector<long long>p1, p2;
public:
    static void init(int size) {
        p1.assign(size + 1, 1);
        p2.assign(size + 1, 1);
        for (int i = 0; i < size; i++) {
            p1[i + 1] = p1[i] * b1 % m1;
            p2[i + 1] = p2[i] * b2 % m2;
        }
    }
    RH() { if (p1.empty()) init(100005); }
    RH(const vector<int>& s) {
        if (p1.empty()) init(200005);
        h1.assign(s.size() + 1, 0);
        h2.assign(s.size() + 1, 0);
        for (int i = 0; i < s.size(); i++) {
            h1[i + 1] = (h1[i] + s[i]) * b1 % m1;
            h2[i + 1] = (h2[i] + s[i]) * b2 % m2;
        }
    }
    H get(int l, int r) {
        int t1 = ((h1[r] - h1[l] * p1[r - l]) % m1 + m1) % m1;
        int t2 = ((h2[r] - h2[l] * p2[r - l]) % m2 + m2) % m2;
        return H{ t1,t2 };
    }//[l,r)

    static H connect(H l, H r, int r_len) {
        return H((l.fs * p1[r_len] + r.fs % m1) % m1,
            (l.sc * p2[r_len] + r.sc % m2) % m2);
    }

    static H ch(vector<int> s) { return RH(s).get(0, s.size()); }
}; long long RH::b1 = 1007, RH::b2 = 1009, RH::m1 = 1e9 + 7, RH::m2 = 1e9 + 9; vector<long long>RH::p1, RH::p2;

signed 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 <= 2) {
        vi c = a, d = b;
        sort(all(c)); sort(all(d));
        rep(i, n) if (c[i] != d[i]) {
            cout << "No" << endl;
            return 0;
        }
        cout << "Yes" << endl;
    }
    else if (k < n - 1) {
        sort(all(a)); sort(all(b));
        bool flag = false;
        rep(i, n) if (a[i] != b[i]) {
            cout<<"No"<<endl;
            flag = true;
            break;
        }
        if (!flag) cout<<"Yes"<<endl;
    }
    else if (k == n - 1) {
        vi c = a, d = b;
        sort(all(c)); sort(all(d));
        rep(i, n) if (c[i] != d[i]) {
            cout<<"No"<<endl;
            return 0;
        }
        b.resize(2 * n);
        rep(i, n) b[i + n] = b[i];
        RH a2(a), b2(b);
        rep(i, n) {
            if (b2.get(i, i + n) == a2.get(0, n)) {
                bool flag = false;
                for (int j = 0; j < n; j++) {
                    if (a[j] != b[i + j]) flag = true;
                }
                if (!flag) {
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
        cout<<"No"<<endl;
    }
    else  {
        rep(i, n) {
            if (a[i] != b[i]) goto loop;
        }
        cout<<"Yes"<<endl;
        return 0;
    loop:;
        if (k > n) {
            cout<<"No"<<endl;
            return 0;
        }
        reverse(all(a));
        rep(i, n) {
            if (a[i] != b[i]) {
                cout<<"No"<<endl;
                return 0;
            }
        }
        cout << "Yes\n";
    }
}
0