# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
241108 | 2020-06-22T16:48:47 Z | DavidDamian | Lozinke (COCI17_lozinke) | C++11 | 46 ms | 23804 KB |
#include <bits/stdc++.h> using namespace std; ///Trie struct node { int bucket[27]; int wordCount; int last; }; node trie[2000005]; int actNode=0; void Insert(string s,int id) { for(int a=0;a<s.size();a++){ int u=0; for(int i=a;i<s.size();i++){ int letter=s[i]-'a'; if(trie[u].bucket[letter]==0) trie[u].bucket[letter]=++actNode; u=trie[u].bucket[letter]; if(trie[u].last!=id) trie[u].wordCount++; trie[u].last=id; } } } int query(string s) { int u=0; for(int i=0;i<s.size();i++){ int letter=s[i]-'a'; if(trie[u].bucket[letter]==0) return 0; u=trie[u].bucket[letter]; } return trie[u].wordCount-1; } int n; vector<string> A; int main() { ios_base::sync_with_stdio(0);cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ string s; cin>>s; Insert(s,i); A.push_back(s); } int total=0; for(string s: A){ total+=query(s); } cout<<total<<'\n'; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 384 KB | Output is correct |
2 | Correct | 5 ms | 384 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Correct | 5 ms | 512 KB | Output is correct |
5 | Correct | 6 ms | 1024 KB | Output is correct |
6 | Correct | 6 ms | 1024 KB | Output is correct |
7 | Correct | 7 ms | 2048 KB | Output is correct |
8 | Correct | 8 ms | 3328 KB | Output is correct |
9 | Correct | 11 ms | 3452 KB | Output is correct |
10 | Correct | 21 ms | 10748 KB | Output is correct |
11 | Correct | 15 ms | 5884 KB | Output is correct |
12 | Correct | 44 ms | 23804 KB | Output is correct |
13 | Correct | 19 ms | 3964 KB | Output is correct |
14 | Correct | 35 ms | 21492 KB | Output is correct |
15 | Correct | 46 ms | 23528 KB | Output is correct |
16 | Correct | 19 ms | 2044 KB | Output is correct |
17 | Correct | 18 ms | 1788 KB | Output is correct |
18 | Correct | 15 ms | 1660 KB | Output is correct |
19 | Correct | 28 ms | 12280 KB | Output is correct |
20 | Correct | 14 ms | 1916 KB | Output is correct |