結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー t98slidert98slider
提出日時 2022-10-15 13:29:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 507 ms / 3,000 ms
コード長 2,114 bytes
コンパイル時間 1,806 ms
コンパイル使用メモリ 174,044 KB
実行使用メモリ 193,712 KB
最終ジャッジ日時 2023-09-09 02:32:15
合計ジャッジ時間 21,233 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
81,212 KB
testcase_01 AC 74 ms
81,236 KB
testcase_02 AC 179 ms
109,740 KB
testcase_03 AC 223 ms
130,088 KB
testcase_04 AC 185 ms
108,300 KB
testcase_05 AC 136 ms
93,900 KB
testcase_06 AC 206 ms
109,608 KB
testcase_07 AC 222 ms
191,516 KB
testcase_08 AC 92 ms
82,372 KB
testcase_09 AC 226 ms
148,348 KB
testcase_10 AC 115 ms
88,568 KB
testcase_11 AC 129 ms
100,976 KB
testcase_12 AC 167 ms
107,588 KB
testcase_13 AC 249 ms
146,608 KB
testcase_14 AC 163 ms
102,168 KB
testcase_15 AC 196 ms
108,392 KB
testcase_16 AC 266 ms
139,488 KB
testcase_17 AC 173 ms
148,284 KB
testcase_18 AC 233 ms
178,392 KB
testcase_19 AC 138 ms
100,344 KB
testcase_20 AC 264 ms
160,808 KB
testcase_21 AC 105 ms
83,852 KB
testcase_22 AC 293 ms
154,768 KB
testcase_23 AC 283 ms
154,544 KB
testcase_24 AC 285 ms
152,688 KB
testcase_25 AC 287 ms
153,380 KB
testcase_26 AC 288 ms
153,140 KB
testcase_27 AC 284 ms
152,488 KB
testcase_28 AC 296 ms
152,972 KB
testcase_29 AC 291 ms
152,780 KB
testcase_30 AC 287 ms
154,016 KB
testcase_31 AC 294 ms
151,984 KB
testcase_32 AC 287 ms
152,476 KB
testcase_33 AC 328 ms
152,216 KB
testcase_34 AC 288 ms
153,196 KB
testcase_35 AC 292 ms
157,296 KB
testcase_36 AC 287 ms
153,352 KB
testcase_37 AC 288 ms
152,924 KB
testcase_38 AC 286 ms
153,460 KB
testcase_39 AC 289 ms
154,812 KB
testcase_40 AC 289 ms
153,996 KB
testcase_41 AC 285 ms
154,000 KB
testcase_42 AC 277 ms
136,880 KB
testcase_43 AC 281 ms
138,248 KB
testcase_44 AC 275 ms
137,140 KB
testcase_45 AC 276 ms
136,972 KB
testcase_46 AC 279 ms
138,960 KB
testcase_47 AC 207 ms
193,592 KB
testcase_48 AC 206 ms
192,980 KB
testcase_49 AC 206 ms
193,712 KB
testcase_50 AC 207 ms
192,880 KB
testcase_51 AC 204 ms
192,444 KB
testcase_52 AC 80 ms
82,176 KB
testcase_53 AC 79 ms
82,200 KB
testcase_54 AC 78 ms
82,400 KB
testcase_55 AC 164 ms
192,512 KB
testcase_56 AC 147 ms
193,092 KB
testcase_57 AC 147 ms
193,304 KB
testcase_58 AC 179 ms
189,272 KB
testcase_59 AC 294 ms
138,068 KB
testcase_60 AC 89 ms
81,216 KB
testcase_61 AC 147 ms
192,848 KB
testcase_62 AC 81 ms
82,964 KB
testcase_63 AC 138 ms
81,796 KB
testcase_64 AC 105 ms
81,568 KB
testcase_65 AC 107 ms
82,904 KB
testcase_66 AC 507 ms
192,484 KB
testcase_67 AC 100 ms
81,356 KB
testcase_68 AC 103 ms
83,108 KB
testcase_69 AC 100 ms
81,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

struct Trie{
    struct Node {
        std::array<int,26> child;
        int sz;
        Node(void) :sz(0) { child.fill(-1); }
        const int& operator[](int k) const { return child[k]; }
        int& operator[](int k) { return child[k]; }
    };
    int num;
    vector<Node> tree;
    Trie() : num(0) {
        tree.push_back(Node());
    }
    void insert(const string &s){
        int cur=0;
        for(auto c:s){
            if(tree[cur][c-'a']==-1){
                tree[cur][c-'a']=++num;
                tree.push_back(Node());
            }
            cur=tree[cur][c-'a'];
        }
        tree[cur].sz++;
    }
    int size(const string &s){
        int cur=0;
        for(auto c:s){
            if(tree[cur][c-'a']==-1)return 0;
            cur=tree[cur][c-'a'];
        }
        return tree[cur].sz;
    }
    int size(int node_num){
        return (node_num==-1?0:tree[node_num].sz);
    }
    bool dfs(int v, bool f, int d, string &s){
        if(d == s.size())return (tree[v].sz >= 1 ? true : false);
        int c0 = s[d] - 'a';
        if(f){
            return tree[v][c0] == -1 ? false : dfs(tree[v][c0], true, d + 1, s);
        }
        for(int i = 0; i < 26; i++){
            if(tree[v][i] == -1)continue;
            if(c0 != i){
                if(d + 1 >= s.size())continue;
                int c1 = s[d + 1] - 'a';
                if(tree[v][c1] == -1)continue;
                int nxt = tree[tree[v][c1]][c0];
                if(nxt == -1)continue;
                if(dfs(nxt, true, d + 2, s))return true;
            }else{
                if(dfs(tree[v][i], f, d + 1, s))return true;
            }
        }
        return false;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int Q;
    cin >> Q;
    vector<Trie> trie(500000);
    string s;
    while(Q--){
        cin >> s;
        if(s.size() > 500000){
            cout << "No" << '\n';
            continue;
        }
        cout << (trie[s.size() - 1].dfs(0, false, 0, s) ? "Yes" : "No") << '\n';
        trie[s.size() - 1].insert(s);
    }
}
0