結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー dyktr_06dyktr_06
提出日時 2022-10-14 23:40:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 421 ms / 3,000 ms
コード長 3,826 bytes
コンパイル時間 2,821 ms
コンパイル使用メモリ 183,148 KB
実行使用メモリ 68,812 KB
最終ジャッジ日時 2024-06-26 17:38:28
合計ジャッジ時間 21,503 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
50,048 KB
testcase_01 AC 37 ms
50,176 KB
testcase_02 AC 201 ms
60,232 KB
testcase_03 AC 230 ms
62,008 KB
testcase_04 AC 204 ms
60,724 KB
testcase_05 AC 151 ms
58,132 KB
testcase_06 AC 217 ms
61,292 KB
testcase_07 AC 196 ms
56,560 KB
testcase_08 AC 73 ms
53,856 KB
testcase_09 AC 203 ms
59,840 KB
testcase_10 AC 110 ms
55,544 KB
testcase_11 AC 97 ms
54,588 KB
testcase_12 AC 164 ms
58,740 KB
testcase_13 AC 265 ms
62,472 KB
testcase_14 AC 183 ms
59,192 KB
testcase_15 AC 240 ms
62,336 KB
testcase_16 AC 331 ms
65,692 KB
testcase_17 AC 136 ms
54,652 KB
testcase_18 AC 215 ms
57,980 KB
testcase_19 AC 134 ms
56,780 KB
testcase_20 AC 278 ms
63,336 KB
testcase_21 AC 106 ms
56,476 KB
testcase_22 AC 360 ms
66,768 KB
testcase_23 AC 367 ms
66,760 KB
testcase_24 AC 360 ms
66,768 KB
testcase_25 AC 349 ms
66,764 KB
testcase_26 AC 371 ms
66,764 KB
testcase_27 AC 354 ms
66,756 KB
testcase_28 AC 347 ms
66,768 KB
testcase_29 AC 365 ms
66,768 KB
testcase_30 AC 348 ms
66,760 KB
testcase_31 AC 359 ms
66,764 KB
testcase_32 AC 343 ms
66,764 KB
testcase_33 AC 350 ms
66,764 KB
testcase_34 AC 356 ms
66,760 KB
testcase_35 AC 361 ms
66,716 KB
testcase_36 AC 378 ms
66,764 KB
testcase_37 AC 358 ms
66,768 KB
testcase_38 AC 367 ms
66,768 KB
testcase_39 AC 367 ms
66,764 KB
testcase_40 AC 352 ms
66,636 KB
testcase_41 AC 357 ms
66,772 KB
testcase_42 AC 303 ms
60,528 KB
testcase_43 AC 299 ms
60,532 KB
testcase_44 AC 302 ms
60,532 KB
testcase_45 AC 300 ms
60,660 KB
testcase_46 AC 297 ms
60,532 KB
testcase_47 AC 257 ms
56,324 KB
testcase_48 AC 257 ms
56,452 KB
testcase_49 AC 256 ms
56,328 KB
testcase_50 AC 250 ms
56,324 KB
testcase_51 AC 256 ms
56,324 KB
testcase_52 AC 84 ms
66,860 KB
testcase_53 AC 86 ms
66,736 KB
testcase_54 AC 85 ms
66,876 KB
testcase_55 AC 122 ms
51,408 KB
testcase_56 AC 120 ms
51,532 KB
testcase_57 AC 119 ms
51,404 KB
testcase_58 AC 80 ms
59,052 KB
testcase_59 AC 421 ms
68,812 KB
testcase_60 AC 67 ms
53,520 KB
testcase_61 AC 120 ms
51,404 KB
testcase_62 AC 42 ms
50,556 KB
testcase_63 AC 110 ms
55,616 KB
testcase_64 AC 80 ms
55,620 KB
testcase_65 AC 86 ms
55,548 KB
testcase_66 AC 114 ms
51,280 KB
testcase_67 AC 92 ms
56,396 KB
testcase_68 AC 78 ms
51,404 KB
testcase_69 AC 91 ms
56,264 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void in(T& ...)':
main.cpp:28:55: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   28 | template<class... T> void in(T&... a){ (cin >> ... >> a); }
      |                                                       ^
main.cpp: In function 'void out(const T&, const Ts& ...)':
main.cpp:30:112: warning: fold-expressions only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   30 | template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
      |                                                                                                                ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()
#define Sort(a) sort(a.begin(), a.end())
#define RSort(a) sort(a.rbegin(), a.rend())

typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<char> vc;
typedef vector<string> vst;
typedef vector<double> vd;
typedef pair<long long, long long> P;

const long long INF = 0x1fffffffffffffff;
const long long MOD = 998244353;
const long double PI = acos(-1);
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T, class U> inline T vin(T& vec, U n) { vec.resize(n); for(int i = 0; i < (int) n; ++i) cin >> vec[i]; return vec; }
template<class T> inline void vout(T vec, string s = "\n"){ for(auto x : vec) cout << x << s; }
template<class... T> void in(T&... a){ (cin >> ... >> a); }
void out(){ cout << '\n'; }
template<class T, class... Ts> void out(const T& a, const Ts&... b){ cout << a; (cout << ... << (cout << ' ', b)); cout << '\n'; }
template<class T, class U> void inGraph(vector<vector<T>>& G, U n, U m, bool directed = false){ G.resize(n); for(int i = 0; i < m; i++){ int a, b; cin >> a >> b; a--, b--; G[a].push_back(b); if(!directed) G[b].push_back(a); } }

struct RollingHash{
    vector<unsigned long> hashed, power;
    static constexpr unsigned long mod = (1uL << 61) - 1;
	
    unsigned long mul(__int128_t a, __int128_t b) const {
		__int128_t t = a * b;
		t = (t >> 61) + (t & mod);
		
		if(t >= mod) return t - mod;
		return t;
	}

    RollingHash(const string &s, unsigned base = 10007){
        int siz = (int) s.size();
        hashed.assign(siz + 1, 0);
        power.assign(siz + 1, 0);
        power[0] = 1;
        for(int i = 0; i < siz; 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;
        }
    }

    unsigned long get(int l, int r) const {
        unsigned long ret = hashed[r] + mod - mul(hashed[l], power[r - l]);
        if(ret >= mod) ret -= mod;
        return ret;
    }

    unsigned long connect(unsigned long h1, unsigned long h2, int h2len) const {
        unsigned long ret = mul(h1, power[h2len]) + h2;
        if(ret >= mod) ret -= mod;
        return ret;
    }

    int LCP(const RollingHash &b, int l1, int r1, int l2, int r2){
        int len = min(r1 - l1, r2 - l2);
        int low = -1, high = len + 1;
        while(high - low > 1){
            int mid = (low + high) / 2;
            if(get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid;
            else high = mid;
        }
        return low;
    }
};

ll n;
vst s;

void input(){
    in(n);
    vin(s, n);
}
 
void solve(){
    vector<map<unsigned long, ll>> mp(1000001);
    rep(i, n){
        string ans = "No";
        RollingHash rh(s[i]);
        ll m = s[i].size();
        rep(j, m - 1){
            ll hashed = rh.get(0, j);
            ll a = rh.get(j, j + 1), b = rh.get(j + 1, j + 2);
            hashed = rh.connect(hashed, b, 1);
            hashed = rh.connect(hashed, a, 1);
            if(j != m - 2){
                ll c = rh.get(j + 2, m);
                hashed = rh.connect(hashed, c, m - j - 2);
            }
            if(mp[m].count(hashed) != 0){
                ans = "Yes";
                break;
            }
        }
        if(mp[m].count(rh.get(0, m)) != 0){
            ans = "Yes";
        }
        mp[m][rh.get(0, m)] = 1;
        out(ans);
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    input();
    solve();
}
0