結果

問題 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  
実行時間 471 ms / 3,000 ms
コード長 3,826 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 181,752 KB
実行使用メモリ 68,596 KB
最終ジャッジ日時 2023-09-09 00:09:38
合計ジャッジ時間 22,209 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
49,728 KB
testcase_01 AC 18 ms
49,748 KB
testcase_02 AC 203 ms
60,020 KB
testcase_03 AC 233 ms
61,628 KB
testcase_04 AC 205 ms
60,368 KB
testcase_05 AC 139 ms
57,808 KB
testcase_06 AC 220 ms
61,228 KB
testcase_07 AC 188 ms
56,392 KB
testcase_08 AC 56 ms
53,652 KB
testcase_09 AC 208 ms
59,620 KB
testcase_10 AC 95 ms
55,376 KB
testcase_11 AC 85 ms
54,408 KB
testcase_12 AC 166 ms
58,620 KB
testcase_13 AC 269 ms
62,092 KB
testcase_14 AC 168 ms
59,104 KB
testcase_15 AC 251 ms
62,100 KB
testcase_16 AC 365 ms
65,792 KB
testcase_17 AC 125 ms
54,384 KB
testcase_18 AC 238 ms
57,780 KB
testcase_19 AC 123 ms
56,564 KB
testcase_20 AC 293 ms
63,096 KB
testcase_21 AC 88 ms
56,108 KB
testcase_22 AC 392 ms
66,468 KB
testcase_23 AC 385 ms
66,632 KB
testcase_24 AC 372 ms
66,440 KB
testcase_25 AC 388 ms
66,484 KB
testcase_26 AC 405 ms
66,532 KB
testcase_27 AC 393 ms
66,472 KB
testcase_28 AC 371 ms
66,488 KB
testcase_29 AC 381 ms
66,452 KB
testcase_30 AC 387 ms
66,628 KB
testcase_31 AC 378 ms
66,448 KB
testcase_32 AC 389 ms
66,440 KB
testcase_33 AC 382 ms
66,440 KB
testcase_34 AC 366 ms
66,528 KB
testcase_35 AC 379 ms
66,416 KB
testcase_36 AC 403 ms
66,544 KB
testcase_37 AC 369 ms
66,488 KB
testcase_38 AC 402 ms
66,472 KB
testcase_39 AC 391 ms
66,412 KB
testcase_40 AC 384 ms
66,456 KB
testcase_41 AC 387 ms
66,548 KB
testcase_42 AC 300 ms
60,376 KB
testcase_43 AC 304 ms
60,224 KB
testcase_44 AC 292 ms
60,244 KB
testcase_45 AC 309 ms
60,324 KB
testcase_46 AC 313 ms
60,388 KB
testcase_47 AC 255 ms
56,208 KB
testcase_48 AC 249 ms
56,224 KB
testcase_49 AC 256 ms
56,292 KB
testcase_50 AC 261 ms
55,996 KB
testcase_51 AC 262 ms
56,240 KB
testcase_52 AC 61 ms
66,392 KB
testcase_53 AC 61 ms
66,668 KB
testcase_54 AC 61 ms
66,584 KB
testcase_55 AC 113 ms
51,180 KB
testcase_56 AC 112 ms
51,148 KB
testcase_57 AC 113 ms
51,144 KB
testcase_58 AC 59 ms
58,768 KB
testcase_59 AC 471 ms
68,596 KB
testcase_60 AC 48 ms
53,320 KB
testcase_61 AC 112 ms
51,164 KB
testcase_62 AC 24 ms
50,364 KB
testcase_63 AC 102 ms
55,412 KB
testcase_64 AC 65 ms
55,348 KB
testcase_65 AC 69 ms
55,400 KB
testcase_66 AC 107 ms
51,168 KB
testcase_67 AC 75 ms
56,136 KB
testcase_68 AC 58 ms
51,140 KB
testcase_69 AC 73 ms
56,180 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘void in(T& ...)’ 内:
main.cpp:28:55: 警告: 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: 関数 ‘void out(const T&, const Ts& ...)’ 内:
main.cpp:30:112: 警告: 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