結果

問題 No.2102 [Cherry Alpha *] Conditional Reflection
ユーザー みここみここ
提出日時 2022-12-12 05:13:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 968 ms / 3,000 ms
コード長 1,666 bytes
コンパイル時間 1,002 ms
コンパイル使用メモリ 85,360 KB
実行使用メモリ 142,872 KB
最終ジャッジ日時 2024-04-23 22:56:20
合計ジャッジ時間 32,111 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
8,860 KB
testcase_01 AC 6 ms
8,892 KB
testcase_02 AC 339 ms
36,904 KB
testcase_03 AC 392 ms
55,156 KB
testcase_04 AC 348 ms
35,088 KB
testcase_05 AC 286 ms
20,572 KB
testcase_06 AC 383 ms
36,872 KB
testcase_07 AC 354 ms
118,292 KB
testcase_08 AC 167 ms
9,816 KB
testcase_09 AC 374 ms
74,360 KB
testcase_10 AC 191 ms
16,856 KB
testcase_11 AC 144 ms
28,764 KB
testcase_12 AC 280 ms
36,144 KB
testcase_13 AC 454 ms
76,028 KB
testcase_14 AC 313 ms
27,668 KB
testcase_15 AC 428 ms
37,808 KB
testcase_16 AC 539 ms
65,968 KB
testcase_17 AC 242 ms
76,356 KB
testcase_18 AC 400 ms
105,204 KB
testcase_19 AC 219 ms
24,964 KB
testcase_20 AC 485 ms
81,652 KB
testcase_21 AC 270 ms
10,752 KB
testcase_22 AC 579 ms
78,504 KB
testcase_23 AC 584 ms
78,344 KB
testcase_24 AC 578 ms
78,064 KB
testcase_25 AC 588 ms
78,500 KB
testcase_26 AC 590 ms
77,912 KB
testcase_27 AC 584 ms
78,352 KB
testcase_28 AC 589 ms
78,188 KB
testcase_29 AC 595 ms
77,416 KB
testcase_30 AC 592 ms
78,660 KB
testcase_31 AC 593 ms
78,548 KB
testcase_32 AC 581 ms
77,616 KB
testcase_33 AC 588 ms
77,924 KB
testcase_34 AC 579 ms
77,828 KB
testcase_35 AC 587 ms
77,980 KB
testcase_36 AC 582 ms
77,884 KB
testcase_37 AC 592 ms
77,820 KB
testcase_38 AC 582 ms
78,760 KB
testcase_39 AC 587 ms
77,932 KB
testcase_40 AC 581 ms
78,112 KB
testcase_41 AC 599 ms
77,796 KB
testcase_42 AC 488 ms
63,716 KB
testcase_43 AC 483 ms
63,912 KB
testcase_44 AC 470 ms
64,464 KB
testcase_45 AC 467 ms
63,968 KB
testcase_46 AC 478 ms
63,400 KB
testcase_47 AC 329 ms
109,792 KB
testcase_48 AC 331 ms
109,608 KB
testcase_49 AC 323 ms
109,596 KB
testcase_50 AC 332 ms
109,664 KB
testcase_51 AC 325 ms
109,688 KB
testcase_52 AC 194 ms
142,752 KB
testcase_53 AC 195 ms
142,872 KB
testcase_54 AC 195 ms
142,624 KB
testcase_55 AC 199 ms
141,424 KB
testcase_56 AC 198 ms
141,632 KB
testcase_57 AC 198 ms
141,640 KB
testcase_58 AC 160 ms
108,080 KB
testcase_59 AC 505 ms
60,420 KB
testcase_60 AC 164 ms
8,844 KB
testcase_61 AC 198 ms
141,412 KB
testcase_62 AC 19 ms
10,616 KB
testcase_63 AC 133 ms
9,244 KB
testcase_64 AC 173 ms
9,188 KB
testcase_65 AC 212 ms
10,240 KB
testcase_66 AC 968 ms
91,364 KB
testcase_67 AC 317 ms
8,992 KB
testcase_68 AC 44 ms
10,444 KB
testcase_69 AC 319 ms
8,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

struct Trie
{
    int c;
    std::vector<std::vector<int>> v;

    Trie(int c) : c(c), v(1)
    {
        v[0].resize(c);
    }

    void insert(string &s)
    {
        int u = 0;
        int n = s.size();
        for(int i = 0; i < n; i++)
        {
            if(!v[u][s[i] - 'a'])
            {
                v[u][s[i] - 'a'] = v.size();
                std::vector<int> w(c);
                v.push_back(w);
            }
            u = v[u][s[i] - 'a'];
        }
    }

    bool find_sub(int i, int u, int n, bool swaped, string &s)
    {
        if(i == n)
        {
            return true;
        }
        bool res = false;
        if(v[u][s[i] - 'a'])
        {
            res |= find_sub(i + 1, v[u][s[i] - 'a'], n, swaped, s);
        }
        if(i < n - 1 && !swaped && s[i] != s[i + 1] && v[u][s[i + 1] - 'a'])
        {
            int r = v[u][s[i + 1] - 'a'];
            if(v[r][s[i] - 'a'])
            {
                res |= find_sub(i + 2, v[r][s[i] - 'a'], n, true, s);
            }
        }
        return res;
    }

    bool find(string &s)
    {
        int n = s.size();
        return find_sub(0, 0, n, false, s);
    }
};

int main()
{
    int n;
    cin >> n;
    vector<Trie> tr(10000, Trie(26));
    int d[1000005];
    for(int i = 0; i <= 1000000; i++)
    {
        d[i] = -1;
    }
    int k = 0;
    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        int l = s.size();
        if(d[l] == -1)
        {
            d[l] = k++;
        }
        cout << (tr[d[l]].find(s) ? "Yes" : "No") << endl;
        tr[d[l]].insert(s);
    }
}
0