結果

問題 No.2254 Reverse Only
ユーザー noya2noya2
提出日時 2023-02-09 01:40:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 3,215 bytes
コンパイル時間 3,981 ms
コンパイル使用メモリ 212,660 KB
実行使用メモリ 12,504 KB
最終ジャッジ日時 2023-10-18 06:34:21
合計ジャッジ時間 8,569 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_08 AC 152 ms
5,836 KB
testcase_09 AC 165 ms
12,504 KB
testcase_10 AC 126 ms
4,928 KB
testcase_11 AC 151 ms
5,836 KB
testcase_12 AC 152 ms
5,836 KB
testcase_13 AC 119 ms
4,928 KB
testcase_14 AC 119 ms
4,928 KB
testcase_15 AC 119 ms
4,928 KB
testcase_16 WA -
testcase_17 AC 164 ms
12,500 KB
testcase_18 AC 151 ms
5,836 KB
testcase_19 AC 143 ms
5,836 KB
testcase_20 AC 158 ms
12,504 KB
testcase_21 AC 156 ms
12,504 KB
testcase_22 AC 80 ms
12,500 KB
testcase_23 AC 144 ms
12,500 KB
testcase_24 AC 133 ms
12,504 KB
testcase_25 AC 144 ms
12,504 KB
testcase_26 WA -
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,476 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 71 ms
4,400 KB
testcase_35 AC 46 ms
4,348 KB
testcase_36 AC 128 ms
5,536 KB
testcase_37 AC 134 ms
5,608 KB
testcase_38 AC 23 ms
4,348 KB
testcase_39 AC 119 ms
5,416 KB
testcase_40 AC 5 ms
4,348 KB
testcase_41 AC 42 ms
4,348 KB
testcase_42 AC 25 ms
4,348 KB
testcase_43 AC 76 ms
4,400 KB
testcase_44 AC 111 ms
4,928 KB
testcase_45 AC 87 ms
4,864 KB
testcase_46 AC 5 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ull = unsigned long long;
void yes(){ printf("Yes\n"); }
void no(){ printf("No\n"); }

struct RollingHash {
    RollingHash(const string &s = ""){ build(s);}
    ull get(int l, int r){ 
        assert(0 <= l && l <= r && r <= n);
        return cal_mod(inner_hash[r] + POSITIVISER - mul_mod(inner_hash[l], pow_base[r-l]));
    }
    static ull get_hash(const string &s){
        int len = s.size();
        set_hash();
        extend_pow_base(len);
        ull res = 0;
        for (int i = 0; i < len; i++) res = cal_mod(mul_mod(res,BASE) + s[i]);
        return res;
    }
  private:
    static constexpr ull MASK30 = (1ULL << 30) - 1;
    static constexpr ull MASK31 = (1ULL << 31) - 1;
    static constexpr ull MASK61 = (1ULL << 61) - 1;
    static constexpr ull MOD = (1ULL << 61) - 1;
    static constexpr ull POSITIVISER = MOD * 4;
    static ull BASE;
    static vector<ull> pow_base;
    static ull mul_mod(ull a, ull b){
        ull au = a >> 31, ad = a & MASK31;
        ull bu = b >> 31, bd = b & MASK31;
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30, midd = mid & MASK30;
        return (au * bu * 2 + midu + (midd << 31) + ad * bd);
    }
    static ull cal_mod(ull x){
        ull xu = x >> 61;
        ull xd = x & MASK61;
        ull res = xu + xd;
        if (res >= MOD) res -= MOD;
        return res;
    }
    static void set_hash(){
        if (BASE == 0) BASE = (1UL<<31) + (random_device()() & MASK31);
    }
    static void extend_pow_base(int len){
        int nlen = pow_base.size();
        if (nlen > len) return ;
        pow_base.resize(len+1);
        for (int i = nlen; i <= len; i++){
            pow_base[i] = cal_mod(mul_mod(pow_base[i-1],BASE));
        }
    }
    string str;
    int n;
    vector<ull> inner_hash;
    void build(const string &s){
        set_hash();
        str = s;
        n = s.size();
        extend_pow_base(n);
        inner_hash.resize(n+1);
        inner_hash[0] = 0;
        for (int i = 0; i < n; i++) inner_hash[i+1] = cal_mod(mul_mod(inner_hash[i],BASE) + s[i]);
    }
};
using ull = unsigned long long;
ull RollingHash::BASE = 0;
vector<ull> RollingHash::pow_base = vector<ull>(1,1);
using roriha = RollingHash;

int main(){
    int n, k; cin >> n >> k;
    vector<int> a(n), b(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    if (a == b){
        yes();
        return 0;
    }
    if (k > n){
        no();
        return 0;
    }
    if (k == n){
        reverse(all(b));
        a == b ? yes() : no();
        return 0;
    }
    string as = "";
    rep(i,n) as += 'a' + a[i];
    as += as;
    string bs = "";
    rep(i,n) bs += 'a' + b[i];
    string cs = bs; reverse(all(cs));
    sort(all(a)), sort(all(b));
    if (a != b){
        no();
        return 0;
    }
    if (k <= n-2){
        yes();
        return 0;
    }
    ull hb = roriha::get_hash(bs);
    ull hc = roriha::get_hash(cs);
    roriha ha(as);
    rep(i,n){
        ull h = ha.get(i,i+n);
        if (h == hb || h == hc){
            yes();
            return 0;
        }
    }
    no();
    return 0;
}
0