Submission #65270271


Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int Q;
cin >> Q;
vector<array<int,26>> xt(1), yt(1);
vector<bool> xterm(1,false), blocked;
vector<vector<int>> yids(1);
int Ycnt = 0, blocked_cnt = 0;
while(Q--){
int T;
string s;
cin >> T >> s;
if(T == 1){
int u = 0;
for(char c : s){
int d = c - 'a';
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int Q;
    cin >> Q;
    vector<array<int,26>> xt(1), yt(1);
    vector<bool> xterm(1,false), blocked;
    vector<vector<int>> yids(1);
    int Ycnt = 0, blocked_cnt = 0;

    while(Q--){
        int T;
        string s;
        cin >> T >> s;
        if(T == 1){
            int u = 0;
            for(char c : s){
                int d = c - 'a';
                if(!xt[u][d]){
                    xt[u][d] = xt.size();
                    xt.emplace_back();
                    xterm.push_back(false);
                }
                u = xt[u][d];
            }
            xterm[u] = true;
            int v = 0;
            bool ok = true;
            for(char c : s){
                int d = c - 'a';
                if(!yt[v][d]){ ok = false; break; }
                v = yt[v][d];
            }
            if(ok){
                for(int id : yids[v])
                    if(!blocked[id]){
                        blocked[id] = true;
                        blocked_cnt++;
                    }
                yids[v].clear();
            }
        } else {
            int yid = Ycnt++;
            blocked.push_back(false);
            int u = 0;
            bool is_block = false;
            for(char c : s){
                if(xterm[u]){ is_block = true; break; }
                int d = c - 'a';
                if(!xt[u][d]){ u = -1; break; }
                u = xt[u][d];
            }
            if(u >= 0 && xterm[u]) is_block = true;
            if(is_block){
                blocked[yid] = true;
                blocked_cnt++;
            } else {
                int v = 0;
                for(char c : s){
                    int d = c - 'a';
                    if(!yt[v][d]){
                        yt[v][d] = yt.size();
                        yt.emplace_back();
                        yids.emplace_back();
                    }
                    v = yt[v][d];
                    yids[v].push_back(yid);
                }
            }
        }
        cout << (Ycnt - blocked_cnt) << "\n";
    }
    return 0;
}

Submission Info

Submission Time
Task E - Forbidden Prefix
User OYU__0YU
Language C++ 20 (gcc 12.2)
Score 500
Code Size 2242 Byte
Status AC
Exec Time 71 ms
Memory 94696 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 57
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 02_handmade_01.txt, 02_handmade_02.txt, 02_handmade_03.txt, 02_handmade_04.txt, 02_handmade_05.txt, 02_handmade_06.txt, 02_handmade_07.txt, 02_handmade_08.txt, 02_handmade_09.txt, 02_handmade_10.txt, 02_handmade_11.txt, 02_handmade_12.txt, 02_handmade_13.txt, 02_handmade_14.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3428 KB
00_sample_02.txt AC 1 ms 3476 KB
01_random_01.txt AC 68 ms 81176 KB
01_random_02.txt AC 70 ms 88776 KB
01_random_03.txt AC 71 ms 88948 KB
01_random_04.txt AC 67 ms 89268 KB
01_random_05.txt AC 53 ms 67896 KB
01_random_06.txt AC 43 ms 56584 KB
01_random_07.txt AC 69 ms 81008 KB
01_random_08.txt AC 68 ms 89844 KB
01_random_09.txt AC 54 ms 59560 KB
01_random_10.txt AC 52 ms 73464 KB
01_random_11.txt AC 51 ms 69008 KB
01_random_12.txt AC 42 ms 56564 KB
01_random_13.txt AC 68 ms 79580 KB
01_random_14.txt AC 30 ms 6688 KB
01_random_15.txt AC 32 ms 10076 KB
01_random_16.txt AC 34 ms 9836 KB
01_random_17.txt AC 37 ms 29888 KB
01_random_18.txt AC 38 ms 16468 KB
01_random_19.txt AC 20 ms 26168 KB
01_random_20.txt AC 19 ms 30108 KB
01_random_21.txt AC 23 ms 30688 KB
01_random_22.txt AC 62 ms 78472 KB
01_random_23.txt AC 17 ms 16928 KB
01_random_24.txt AC 30 ms 9800 KB
01_random_25.txt AC 21 ms 6680 KB
01_random_26.txt AC 22 ms 6852 KB
01_random_27.txt AC 21 ms 12732 KB
01_random_28.txt AC 30 ms 9900 KB
01_random_29.txt AC 25 ms 16572 KB
01_random_30.txt AC 24 ms 6648 KB
01_random_31.txt AC 16 ms 6948 KB
01_random_32.txt AC 18 ms 5268 KB
01_random_33.txt AC 13 ms 13032 KB
01_random_34.txt AC 28 ms 9848 KB
01_random_35.txt AC 20 ms 6884 KB
01_random_36.txt AC 20 ms 6928 KB
01_random_37.txt AC 28 ms 8240 KB
01_random_38.txt AC 48 ms 27692 KB
01_random_39.txt AC 50 ms 33056 KB
01_random_40.txt AC 65 ms 53788 KB
01_random_41.txt AC 68 ms 50672 KB
02_handmade_01.txt AC 44 ms 56936 KB
02_handmade_02.txt AC 69 ms 81628 KB
02_handmade_03.txt AC 23 ms 3624 KB
02_handmade_04.txt AC 25 ms 4256 KB
02_handmade_05.txt AC 5 ms 3440 KB
02_handmade_06.txt AC 6 ms 4684 KB
02_handmade_07.txt AC 3 ms 3460 KB
02_handmade_08.txt AC 5 ms 4120 KB
02_handmade_09.txt AC 4 ms 3668 KB
02_handmade_10.txt AC 7 ms 5444 KB
02_handmade_11.txt AC 7 ms 6620 KB
02_handmade_12.txt AC 14 ms 13232 KB
02_handmade_13.txt AC 24 ms 30048 KB
02_handmade_14.txt AC 59 ms 94696 KB


2025-05-05 (Mon)
19:37:09 +09:00