結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー 👑 NachiaNachia
提出日時 2022-10-15 02:59:16
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
RE  
実行時間 -
コード長 1,766 bytes
コンパイル時間 7,560 ms
コンパイル使用メモリ 162,748 KB
最終ジャッジ日時 2025-02-08 06:03:52
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31 RE * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <atcoder/dsu>
#include <atcoder/string>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
using u128 = __uint128_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


int main(){
    int N; cin >> N;
    vector<string> S(N); rep(i,N) cin >> S[i];

    vector<vector<int>> I(1000001);
    rep(i,N) I[S[i].size()].push_back(i);
    
    vector<int> ans(N, 0);
    
    rep(L,I.size()) if(L>=2) if(!I[L].empty()){
        string s;
        for(auto& i : I[L]){ s += S[i].substr(2); s += S[i].substr(0, L-2); }
        auto sa = atcoder::suffix_array(s);
        auto lcp = atcoder::lcp_array(s, sa);
        map<pair<int, int>, int> Q;
        rep(i,sa.size()){
            if(i != 0) if(lcp[i-1] < L-2) Q.clear();
            int c = sa[i] / (L*2-4), p = sa[i] % (L*2-4);
            if(p >= L-1) continue;
            int si = I[L][c];
            int c1 = S[si][p], c2 = S[si][p+1];
            pair<int, int> key = { p, max(c1,c2)*1000+min(c1,c2) };
            if(Q.count(key)){
                int& v = Q[key];
                ans[max(v, si)] = 1; v = min(v, si);
            } else Q.insert({ key, si });
        }
    }
    
    rep(L,I.size()) if(L==1){
        map<string, int> Q;
        for(int i : I[L]) /* I[L] sorted */ {
            if(Q.count(S[i])) ans[i] = 1; else Q[S[i]] = i;
        }
    }

    vector<int> vis(N);
    rep(i,N){
        cout << (ans[i] ? "Yes\n" : "No\n");
    }

    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0