結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー t98slidert98slider
提出日時 2022-10-15 13:34:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 420 ms / 3,000 ms
コード長 2,084 bytes
コンパイル時間 1,557 ms
コンパイル使用メモリ 173,824 KB
実行使用メモリ 116,820 KB
最終ジャッジ日時 2023-09-09 02:32:55
合計ジャッジ時間 14,822 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 97 ms
31,048 KB
testcase_03 AC 133 ms
58,608 KB
testcase_04 AC 95 ms
30,912 KB
testcase_05 AC 53 ms
10,784 KB
testcase_06 AC 100 ms
32,216 KB
testcase_07 AC 112 ms
114,384 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 129 ms
59,264 KB
testcase_10 AC 39 ms
10,748 KB
testcase_11 AC 48 ms
17,564 KB
testcase_12 AC 86 ms
31,424 KB
testcase_13 AC 148 ms
58,736 KB
testcase_14 AC 71 ms
18,520 KB
testcase_15 AC 106 ms
30,792 KB
testcase_16 AC 169 ms
58,860 KB
testcase_17 AC 71 ms
58,896 KB
testcase_18 AC 135 ms
115,184 KB
testcase_19 AC 56 ms
17,952 KB
testcase_20 AC 163 ms
58,888 KB
testcase_21 AC 30 ms
4,876 KB
testcase_22 AC 188 ms
58,796 KB
testcase_23 AC 187 ms
60,076 KB
testcase_24 AC 193 ms
59,204 KB
testcase_25 AC 186 ms
59,224 KB
testcase_26 AC 184 ms
60,324 KB
testcase_27 AC 188 ms
59,368 KB
testcase_28 AC 189 ms
58,516 KB
testcase_29 AC 193 ms
58,752 KB
testcase_30 AC 193 ms
58,584 KB
testcase_31 AC 188 ms
58,652 KB
testcase_32 AC 194 ms
59,400 KB
testcase_33 AC 185 ms
59,416 KB
testcase_34 AC 188 ms
59,652 KB
testcase_35 AC 189 ms
58,696 KB
testcase_36 AC 191 ms
58,452 KB
testcase_37 AC 190 ms
60,180 KB
testcase_38 AC 194 ms
59,916 KB
testcase_39 AC 188 ms
59,296 KB
testcase_40 AC 188 ms
58,648 KB
testcase_41 AC 189 ms
58,832 KB
testcase_42 AC 195 ms
59,148 KB
testcase_43 AC 190 ms
59,852 KB
testcase_44 AC 193 ms
58,584 KB
testcase_45 AC 201 ms
58,656 KB
testcase_46 AC 184 ms
59,336 KB
testcase_47 AC 128 ms
114,340 KB
testcase_48 AC 126 ms
114,192 KB
testcase_49 AC 133 ms
114,876 KB
testcase_50 AC 129 ms
114,320 KB
testcase_51 AC 134 ms
114,168 KB
testcase_52 AC 78 ms
116,784 KB
testcase_53 AC 76 ms
116,264 KB
testcase_54 AC 76 ms
116,820 KB
testcase_55 AC 75 ms
114,720 KB
testcase_56 AC 75 ms
114,796 KB
testcase_57 AC 75 ms
114,216 KB
testcase_58 AC 99 ms
103,660 KB
testcase_59 AC 222 ms
60,268 KB
testcase_60 AC 14 ms
4,380 KB
testcase_61 AC 72 ms
114,436 KB
testcase_62 AC 5 ms
4,836 KB
testcase_63 AC 54 ms
4,380 KB
testcase_64 AC 29 ms
4,380 KB
testcase_65 AC 31 ms
4,956 KB
testcase_66 AC 420 ms
114,860 KB
testcase_67 AC 25 ms
4,388 KB
testcase_68 AC 31 ms
4,960 KB
testcase_69 AC 24 ms
4,380 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){
            for(int i = d; i < s.size(); i++){
                v = tree[v][s[i] - 'a'];
                if(v == -1)return false;
            }
            return tree[v].sz >= 1 ? true : false;
        }
        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;
    Trie trie;
    string s;
    while(Q--){
        cin >> s;
        cout << (trie.dfs(0, false, 0, s) ? "Yes" : "No") << '\n';
        trie.insert(s);
    }
}
0