結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2022-10-18 00:33:12
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 562 ms / 3,000 ms
コード長 3,001 bytes
コンパイル時間 1,940 ms
コンパイル使用メモリ 177,996 KB
実行使用メモリ 19,776 KB
最終ジャッジ日時 2023-09-10 22:05:03
合計ジャッジ時間 30,283 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 322 ms
7,812 KB
testcase_03 AC 355 ms
8,012 KB
testcase_04 AC 347 ms
7,888 KB
testcase_05 AC 288 ms
5,544 KB
testcase_06 AC 367 ms
7,880 KB
testcase_07 AC 195 ms
5,720 KB
testcase_08 AC 177 ms
4,380 KB
testcase_09 AC 279 ms
8,036 KB
testcase_10 AC 196 ms
4,528 KB
testcase_11 AC 117 ms
5,512 KB
testcase_12 AC 250 ms
6,128 KB
testcase_13 AC 361 ms
8,584 KB
testcase_14 AC 303 ms
5,840 KB
testcase_15 AC 404 ms
8,040 KB
testcase_16 AC 499 ms
9,000 KB
testcase_17 AC 144 ms
5,700 KB
testcase_18 AC 252 ms
6,188 KB
testcase_19 AC 207 ms
5,388 KB
testcase_20 AC 392 ms
8,848 KB
testcase_21 AC 298 ms
4,380 KB
testcase_22 AC 526 ms
9,804 KB
testcase_23 AC 528 ms
9,560 KB
testcase_24 AC 523 ms
9,588 KB
testcase_25 AC 521 ms
9,540 KB
testcase_26 AC 512 ms
9,572 KB
testcase_27 AC 509 ms
9,600 KB
testcase_28 AC 511 ms
9,540 KB
testcase_29 AC 521 ms
9,636 KB
testcase_30 AC 515 ms
9,652 KB
testcase_31 AC 522 ms
9,612 KB
testcase_32 AC 508 ms
9,516 KB
testcase_33 AC 509 ms
9,516 KB
testcase_34 AC 526 ms
9,516 KB
testcase_35 AC 531 ms
9,664 KB
testcase_36 AC 528 ms
9,504 KB
testcase_37 AC 533 ms
9,604 KB
testcase_38 AC 519 ms
9,648 KB
testcase_39 AC 515 ms
9,508 KB
testcase_40 AC 523 ms
9,640 KB
testcase_41 AC 516 ms
9,516 KB
testcase_42 AC 331 ms
7,868 KB
testcase_43 AC 330 ms
7,996 KB
testcase_44 AC 327 ms
7,924 KB
testcase_45 AC 325 ms
7,860 KB
testcase_46 AC 328 ms
7,992 KB
testcase_47 AC 235 ms
5,596 KB
testcase_48 AC 245 ms
5,620 KB
testcase_49 AC 236 ms
5,624 KB
testcase_50 AC 238 ms
5,760 KB
testcase_51 AC 240 ms
5,572 KB
testcase_52 AC 67 ms
19,704 KB
testcase_53 AC 67 ms
19,776 KB
testcase_54 AC 66 ms
19,648 KB
testcase_55 AC 96 ms
4,380 KB
testcase_56 AC 96 ms
4,376 KB
testcase_57 AC 96 ms
4,376 KB
testcase_58 AC 73 ms
12,424 KB
testcase_59 AC 562 ms
12,560 KB
testcase_60 AC 177 ms
4,376 KB
testcase_61 AC 96 ms
4,504 KB
testcase_62 AC 12 ms
4,380 KB
testcase_63 AC 108 ms
4,380 KB
testcase_64 AC 111 ms
4,376 KB
testcase_65 AC 113 ms
4,380 KB
testcase_66 AC 91 ms
4,376 KB
testcase_67 AC 336 ms
4,380 KB
testcase_68 AC 80 ms
4,376 KB
testcase_69 AC 338 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.10.18 00:32:53
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



using ull = unsigned long long;
static const ull _mod = 0x1fffffffffffffff;
mt19937_64 mt{(unsigned int)time(NULL)};
const ull _base = mt() % _mod;

struct RollingHash {
private:
    vector<ull> hashed, power;

    inline ull _mul(ull a, ull b) const {
        ull au = a >> 31;
        ull ad = a & ((1UL << 31) - 1);
        ull bu = b >> 31;
        ull bd = b & ((1UL << 31) - 1);
        ull mid = ad * bu + au * bd;
        ull midu = mid >> 30;
        ull midd = mid & ((1UL << 30) - 1);
        ull ans = au * bu * 2 + midu + (midd << 31) + ad * bd;
        
        ans = (ans >> 61) + (ans & _mod);
        if (ans >= _mod) ans -= _mod;
        return ans;
    }
public:
    RollingHash(const string &s) {
        ll n = s.size();
        hashed.assign(n + 1, 0);
        power.assign(n + 1, 0);
        power[0] = 1;
        for(ll i = 0; i < n; i++) {
            power[i + 1] = _mul(power[i], _base);
            hashed[i + 1] = _mul(hashed[i], _base) + s[i];
            if(hashed[i + 1] >= _mod) hashed[i + 1] -= _mod;
        }
    }
    
    ull get(ll l, ll r) const {
        ull ret = hashed[r] + _mod - _mul(hashed[l], power[r - l]);
        if(ret >= _mod) ret -= _mod;
        return ret;
    }
    
    ull connect(ull h1, ull h2, ll h2len) const {
        ull ret = _mul(h1, power[h2len]) + h2;
        if(ret >= _mod) ret -= _mod;
        return ret;
    }
    
    void connect(const string &s) {
        ll n = hashed.size() - 1, m = s.size();
        hashed.resize(n + m + 1);
        power.resize(n + m + 1);
        for(ll i = n; i < n + m; i++) {
            power[i + 1] = _mul(power[i], _base);
            hashed[i + 1] = _mul(hashed[i], _base) + s[i - n];
            if(hashed[i + 1] >= _mod) hashed[i + 1] -= _mod;
        }
    }
    
    ll LCP(const RollingHash &b, ll l1, ll r1, ll l2, ll r2) {
        ll len = min(r1 - l1, r2 - l2);
        ll low = -1, high = len + 1;
        while(high - low > 1) {
            ll mid = (low + high) / 2;
            if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
            else high = mid;
        }
        return low;
    }
};

int main() {

    int n;cin >> n;
    unordered_set<unsigned long long> st;
    for (int i = 0; i < n; i++) {
        string s;cin >> s;
        int m = s.size();
        RollingHash rh(s);
        bool yes = false;
        if (st.count(rh.get(0,m))) {
            puts("Yes");
            yes = true;
        }
        for (int j = 0; j <= m-2 && !yes; j++) {
            auto t = rh.connect(rh.get(0,j),rh.get(j+1,j+2),1);
            t = rh.connect(t,rh.get(j,j+1),1);
            t = rh.connect(t,rh.get(j+2,m),m-j-2);
            if (st.count(t)) {
                puts("Yes");
                yes = true;
            }
        }
        if (!yes) puts("No");
        st.insert(rh.get(0,m));
    }
    return 0;
}
0