結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー t98slidert98slider
提出日時 2022-10-15 13:25:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 449 ms / 3,000 ms
コード長 1,973 bytes
コンパイル時間 1,618 ms
コンパイル使用メモリ 172,416 KB
実行使用メモリ 117,380 KB
最終ジャッジ日時 2023-09-09 02:31:17
合計ジャッジ時間 15,778 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 101 ms
31,920 KB
testcase_03 AC 140 ms
59,096 KB
testcase_04 AC 100 ms
31,312 KB
testcase_05 AC 55 ms
10,324 KB
testcase_06 AC 111 ms
31,500 KB
testcase_07 AC 128 ms
113,912 KB
testcase_08 AC 18 ms
4,376 KB
testcase_09 AC 131 ms
58,960 KB
testcase_10 AC 38 ms
10,308 KB
testcase_11 AC 51 ms
18,028 KB
testcase_12 AC 92 ms
31,744 KB
testcase_13 AC 160 ms
59,372 KB
testcase_14 AC 77 ms
18,604 KB
testcase_15 AC 119 ms
31,112 KB
testcase_16 AC 180 ms
59,876 KB
testcase_17 AC 77 ms
58,564 KB
testcase_18 AC 156 ms
115,064 KB
testcase_19 AC 58 ms
17,912 KB
testcase_20 AC 168 ms
58,900 KB
testcase_21 AC 31 ms
4,812 KB
testcase_22 AC 205 ms
59,816 KB
testcase_23 AC 207 ms
59,448 KB
testcase_24 AC 207 ms
59,360 KB
testcase_25 AC 206 ms
58,740 KB
testcase_26 AC 206 ms
58,592 KB
testcase_27 AC 204 ms
59,348 KB
testcase_28 AC 196 ms
59,088 KB
testcase_29 AC 199 ms
58,676 KB
testcase_30 AC 226 ms
59,128 KB
testcase_31 AC 220 ms
59,864 KB
testcase_32 AC 219 ms
59,488 KB
testcase_33 AC 205 ms
59,004 KB
testcase_34 AC 204 ms
59,028 KB
testcase_35 AC 201 ms
58,812 KB
testcase_36 AC 222 ms
60,476 KB
testcase_37 AC 205 ms
58,780 KB
testcase_38 AC 205 ms
58,900 KB
testcase_39 AC 203 ms
58,744 KB
testcase_40 AC 213 ms
58,852 KB
testcase_41 AC 206 ms
58,512 KB
testcase_42 AC 224 ms
59,208 KB
testcase_43 AC 228 ms
59,020 KB
testcase_44 AC 225 ms
58,556 KB
testcase_45 AC 237 ms
58,772 KB
testcase_46 AC 219 ms
59,764 KB
testcase_47 AC 157 ms
114,148 KB
testcase_48 AC 160 ms
114,524 KB
testcase_49 AC 153 ms
113,964 KB
testcase_50 AC 153 ms
113,972 KB
testcase_51 AC 153 ms
115,032 KB
testcase_52 AC 81 ms
117,380 KB
testcase_53 AC 79 ms
116,000 KB
testcase_54 AC 78 ms
117,124 KB
testcase_55 AC 79 ms
114,808 KB
testcase_56 AC 80 ms
114,924 KB
testcase_57 AC 78 ms
115,308 KB
testcase_58 AC 103 ms
111,024 KB
testcase_59 AC 244 ms
59,104 KB
testcase_60 AC 14 ms
4,376 KB
testcase_61 AC 78 ms
114,232 KB
testcase_62 AC 5 ms
4,808 KB
testcase_63 AC 69 ms
4,380 KB
testcase_64 AC 32 ms
4,380 KB
testcase_65 AC 33 ms
4,796 KB
testcase_66 AC 449 ms
114,860 KB
testcase_67 AC 25 ms
4,376 KB
testcase_68 AC 27 ms
4,984 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){
            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;
    Trie trie;
    string s;
    while(Q--){
        cin >> s;
        cout << (trie.dfs(0, false, 0, s) ? "Yes" : "No") << '\n';
        trie.insert(s);
    }
}
0