Task: | Buzzwords |
Sender: | joaquimballester |
Submission time: | 2024-11-04 17:43:44 +0200 |
Language: | C++ (C++11) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | WRONG ANSWER | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
#18 | WRONG ANSWER | 0.00 s | details |
#19 | ACCEPTED | 0.00 s | details |
#20 | ACCEPTED | 0.00 s | details |
#21 | WRONG ANSWER | 0.01 s | details |
#22 | WRONG ANSWER | 0.01 s | details |
#23 | WRONG ANSWER | 0.00 s | details |
#24 | WRONG ANSWER | 0.00 s | details |
#25 | WRONG ANSWER | 0.01 s | details |
#26 | WRONG ANSWER | 0.00 s | details |
#27 | WRONG ANSWER | 0.01 s | details |
#28 | WRONG ANSWER | 0.00 s | details |
#29 | WRONG ANSWER | 0.00 s | details |
#30 | WRONG ANSWER | 0.00 s | details |
#31 | WRONG ANSWER | 0.01 s | details |
#32 | WRONG ANSWER | 0.01 s | details |
#33 | WRONG ANSWER | 0.00 s | details |
#34 | WRONG ANSWER | 0.00 s | details |
#35 | WRONG ANSWER | 0.01 s | details |
#36 | WRONG ANSWER | 0.00 s | details |
#37 | WRONG ANSWER | 0.01 s | details |
#38 | WRONG ANSWER | 0.00 s | details |
#39 | WRONG ANSWER | 0.00 s | details |
#40 | WRONG ANSWER | 0.00 s | details |
#41 | WRONG ANSWER | 0.09 s | details |
#42 | WRONG ANSWER | 0.06 s | details |
#43 | WRONG ANSWER | 0.05 s | details |
#44 | WRONG ANSWER | 0.01 s | details |
Code
#include <iostream> #include <vector> #include <string> #include <queue> #include <unordered_map> using namespace std; struct TrieNode { unordered_map<char, TrieNode*> children; TrieNode* failLink = nullptr; int outputCount = 0; bool isEnd = false; }; void insertPattern(TrieNode* root, const string& pattern) { TrieNode* current = root; for (char c : pattern) { if (current->children.find(c) == current->children.end()) { current->children[c] = new TrieNode(); } current = current->children[c]; } current->isEnd = true; current->outputCount++; } void buildFailureLinks(TrieNode* root) { queue<TrieNode*> q; root->failLink = root; for (auto& child : root->children) { child.second->failLink = root; q.push(child.second); } while (!q.empty()) { TrieNode* current = q.front(); q.pop(); for (auto& child : current->children) { char ch = child.first; TrieNode* nextNode = child.second; TrieNode* fail = current->failLink; while (fail != root && fail->children.find(ch) == fail->children.end()) { fail = fail->failLink; } if (fail->children.find(ch) != fail->children.end()) { nextNode->failLink = fail->children[ch]; } else { nextNode->failLink = root; } if (nextNode->failLink->isEnd) { nextNode->outputCount += nextNode->failLink->outputCount; } q.push(nextNode); } } } int searchText(TrieNode* root, const string& text) { TrieNode* current = root; int totalCount = 0; for (char c : text) { while (current != root && current->children.find(c) == current->children.end()) { current = current->failLink; } if (current->children.find(c) != current->children.end()) { current = current->children[c]; } if (current->isEnd) { totalCount += current->outputCount; } } return totalCount; } int main() { string text; getline(cin, text); int q; cin >> q; cin.ignore(); TrieNode* root = new TrieNode(); for (int i = 0; i < q; i++) { string buzzword; getline(cin, buzzword); insertPattern(root, buzzword); } buildFailureLinks(root); int result = searchText(root, text); cout << result << endl; return 0; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
g fhe 395 a aa aafh ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 2
Verdict: ACCEPTED
input |
---|
s adh 372 a ad ae ... |
correct output |
---|
6 |
user output |
---|
6 |
Test 3
Verdict: ACCEPTED
input |
---|
adcdb 20 a aa ab ... |
correct output |
---|
9 |
user output |
---|
9 |
Test 4
Verdict: ACCEPTED
input |
---|
aaaaa 5 a aa aaa ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 5
Verdict: ACCEPTED
input |
---|
o zws 759 a ab abw ... |
correct output |
---|
8 |
user output |
---|
8 |
Test 6
Verdict: ACCEPTED
input |
---|
aaaaa 5 a aa aaa ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 7
Verdict: ACCEPTED
input |
---|
ifv b 649 a aaw ac ... |
correct output |
---|
10 |
user output |
---|
10 |
Test 8
Verdict: ACCEPTED
input |
---|
dbbdc 129 a aa aaab ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 9
Verdict: ACCEPTED
input |
---|
aaaaa 5 a aa aaa ... |
correct output |
---|
15 |
user output |
---|
15 |
Test 10
Verdict: ACCEPTED
input |
---|
eeeab 9 a b c ... |
correct output |
---|
5 |
user output |
---|
5 |
Test 11
Verdict: ACCEPTED
input |
---|
ghfhe d fd 430 a aa aafa ... |
correct output |
---|
22 |
user output |
---|
22 |
Test 12
Verdict: WRONG ANSWER
input |
---|
syadhzdgck 275 a ad adh ... |
correct output |
---|
53 |
user output |
---|
48 |
Test 13
Verdict: ACCEPTED
input |
---|
adcdbbbbba 256 a aa aaa ... |
correct output |
---|
49 |
user output |
---|
49 |
Test 14
Verdict: ACCEPTED
input |
---|
aaaaaaaaaa 10 a aa aaa ... |
correct output |
---|
55 |
user output |
---|
55 |
Test 15
Verdict: ACCEPTED
input |
---|
o zwspspfd 468 a adks afhsrhvwxn ... |
correct output |
---|
45 |
user output |
---|
45 |
Test 16
Verdict: ACCEPTED
input |
---|
aaaaaaaaaa 10 a aa aaa ... |
correct output |
---|
55 |
user output |
---|
55 |
Test 17
Verdict: ACCEPTED
input |
---|
i vbbjczpc 703 a aa abou ... |
correct output |
---|
29 |
user output |
---|
29 |
Test 18
Verdict: WRONG ANSWER
input |
---|
d bdcbdbcb 128 a aa aab ... |
correct output |
---|
42 |
user output |
---|
38 |
Test 19
Verdict: ACCEPTED
input |
---|
aaaaaaaaaa 10 a aa aaa ... |
correct output |
---|
55 |
user output |
---|
55 |
Test 20
Verdict: ACCEPTED
input |
---|
eeeabcbabh 171 a aac aahg ... |
correct output |
---|
34 |
user output |
---|
34 |
Test 21
Verdict: WRONG ANSWER
input |
---|
ghfhehdf ddciaicdehheefdihadaf... |
correct output |
---|
246 |
user output |
---|
44 |
Test 22
Verdict: WRONG ANSWER
input |
---|
s adhzdgckekirkyowkirnflwfanrx... |
correct output |
---|
52 |
user output |
---|
11 |
Test 23
Verdict: WRONG ANSWER
input |
---|
adcdbbbbbaaccabbbccd cabccacdb... |
correct output |
---|
178 |
user output |
---|
20 |
Test 24
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
2518 |
user output |
---|
87 |
Test 25
Verdict: WRONG ANSWER
input |
---|
oezws spfdzfasgxlquafowjzpe pv... |
correct output |
---|
284 |
user output |
---|
63 |
Test 26
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
1387 |
user output |
---|
35 |
Test 27
Verdict: WRONG ANSWER
input |
---|
ifvbbjczpcnpknimqvlttkngpe szx... |
correct output |
---|
258 |
user output |
---|
58 |
Test 28
Verdict: WRONG ANSWER
input |
---|
dbbdcbdb bcaabb bccddbbbacbcdc... |
correct output |
---|
36 |
user output |
---|
5 |
Test 29
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
3076 |
user output |
---|
136 |
Test 30
Verdict: WRONG ANSWER
input |
---|
e eabcbabhdbcbaddebchdiga ggfb... |
correct output |
---|
23 |
user output |
---|
10 |
Test 31
Verdict: WRONG ANSWER
input |
---|
ghfhehdff dci icdehheefdih daf... |
correct output |
---|
248 |
user output |
---|
41 |
Test 32
Verdict: WRONG ANSWER
input |
---|
s a hzdgckekirkyo kirnflw anrx... |
correct output |
---|
27 |
user output |
---|
8 |
Test 33
Verdict: WRONG ANSWER
input |
---|
adcdbbb baac abbbcc c abccacd ... |
correct output |
---|
433 |
user output |
---|
69 |
Test 34
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
3427 |
user output |
---|
55 |
Test 35
Verdict: WRONG ANSWER
input |
---|
oezwsp pf z asgxlquafowjzpekpv... |
correct output |
---|
359 |
user output |
---|
75 |
Test 36
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
2126 |
user output |
---|
26 |
Test 37
Verdict: WRONG ANSWER
input |
---|
ifvbbjczpcnpk imqvlttkngpeqszx... |
correct output |
---|
395 |
user output |
---|
108 |
Test 38
Verdict: WRONG ANSWER
input |
---|
dbbdcbd cbcaabbabccddbb acbcdc... |
correct output |
---|
242 |
user output |
---|
38 |
Test 39
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
4287 |
user output |
---|
50 |
Test 40
Verdict: WRONG ANSWER
input |
---|
eeeabcbabhd cb ddebchdigaiggfb... |
correct output |
---|
15 |
user output |
---|
9 |
Test 41
Verdict: WRONG ANSWER
input |
---|
ghfhehdffdd i icdehheefd hadaf... |
correct output |
---|
431 |
user output |
---|
22 |
Test 42
Verdict: WRONG ANSWER
input |
---|
syadhzdgckekirkyow irnflwfanrx... |
correct output |
---|
8039 |
user output |
---|
1492 |
Test 43
Verdict: WRONG ANSWER
input |
---|
adcdbbbbbaaccabb ccdccabcc cdb... |
correct output |
---|
9409 |
user output |
---|
1472 |
Test 44
Verdict: WRONG ANSWER
input |
---|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa... |
correct output |
---|
168696 |
user output |
---|
503 |