QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#534787 | #7076. Browser Games | xiojoy# | WA | 0ms | 3832kb | C++20 | 1.8kb | 2024-08-27 16:17:15 | 2024-08-27 16:17:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define cctie ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(x) x.begin(), x.end()
#define ALL(x) x.begin() + 1, x.end()
using i64 = long long;
using i128 = __int128;
map<array<int, 2>, int> L, R;
struct Info {
int x = 0;
int y = 0;
array<int, 26> next{};
};
struct Trie {
int sum = 0;
vector<Info> t;
Trie() {
init();
}
void init() {
t.clear();
newNode();
}
int newNode() {
t.emplace_back();
return t.size() - 1;
}
int next(int p, int u) {
return t[p].next[u];
}
void insert(const string &s) {
int p = 0;
for (char c : s) {
int u = c - 'a';
if (!t[p].next[u]) {
t[p].next[u] = newNode();
}
p = t[p].next[u];
t[p].x++;
}
};
void erase(const string &s) {
int p = 0;
for (char c : s) {
int u = c - 'a';
p = t[p].next[u];
t[p].x--;
if (!t[p].x) {
break;
}
}
sum -= dfs(p);
t[p].next.fill(0);
t[p].y = 1;
sum++;
}
int dfs(int p) {
int cnt = t[p].y;
for (int i = 0; i < 26; i++) {
if (t[p].next[i]) {
cnt += dfs(t[p].next[i]);
}
}
return cnt;
}
};
void prework() {
}
int main() {
cctie;
prework();
int n;
cin >> n;
Trie T;
vector<string> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
T.insert(a[i]);
}
for (int i = 1; i <= n; i++) {
T.erase(a[i]);
cout << T.sum << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
3 ufoipv.ofu hsbocmvfgboubtz.kq hfotijo.njipzp.dpn/kb
output:
1 2 2
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
3 hfotijo.njipzp.dpn/kb hsbocmvfgboubtz.kq ufoipv.ofu
output:
1 1 2
result:
ok 3 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
1 a
output:
1
result:
ok single line: '1'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3832kb
input:
2 a b
output:
1 2
result:
ok 2 lines
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3596kb
input:
3 a.b/e a.c/e a.d/e
output:
1 2 2
result:
wrong answer 3rd lines differ - expected: '1', found: '2'