結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2022-10-17 23:59:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,008 bytes
コンパイル時間 1,833 ms
コンパイル使用メモリ 176,476 KB
実行使用メモリ 19,968 KB
最終ジャッジ日時 2023-09-10 21:42:24
合計ジャッジ時間 45,550 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 558 ms
7,940 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 505 ms
5,416 KB
testcase_06 WA -
testcase_07 AC 264 ms
5,572 KB
testcase_08 AC 320 ms
4,384 KB
testcase_09 WA -
testcase_10 AC 352 ms
4,744 KB
testcase_11 WA -
testcase_12 AC 419 ms
6,480 KB
testcase_13 WA -
testcase_14 AC 523 ms
5,880 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 205 ms
5,624 KB
testcase_18 WA -
testcase_19 AC 351 ms
5,520 KB
testcase_20 WA -
testcase_21 AC 531 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 811 ms
9,532 KB
testcase_30 AC 841 ms
9,560 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 846 ms
9,624 KB
testcase_40 AC 857 ms
9,716 KB
testcase_41 WA -
testcase_42 AC 518 ms
8,000 KB
testcase_43 AC 532 ms
8,132 KB
testcase_44 AC 520 ms
8,100 KB
testcase_45 AC 521 ms
7,912 KB
testcase_46 AC 533 ms
8,072 KB
testcase_47 AC 349 ms
5,692 KB
testcase_48 AC 349 ms
5,732 KB
testcase_49 AC 350 ms
5,684 KB
testcase_50 AC 348 ms
5,836 KB
testcase_51 AC 348 ms
5,684 KB
testcase_52 AC 64 ms
19,968 KB
testcase_53 AC 65 ms
19,788 KB
testcase_54 AC 64 ms
19,804 KB
testcase_55 AC 96 ms
4,380 KB
testcase_56 AC 95 ms
4,380 KB
testcase_57 AC 95 ms
4,376 KB
testcase_58 AC 72 ms
12,380 KB
testcase_59 WA -
testcase_60 AC 313 ms
4,380 KB
testcase_61 AC 94 ms
4,376 KB
testcase_62 AC 19 ms
4,376 KB
testcase_63 WA -
testcase_64 AC 174 ms
4,376 KB
testcase_65 AC 178 ms
4,380 KB
testcase_66 AC 91 ms
4,380 KB
testcase_67 WA -
testcase_68 AC 79 ms
4,376 KB
testcase_69 AC 604 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2022.10.17 23:59:00
**/

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


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

    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