# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
241108 | DavidDamian | Lozinke (COCI17_lozinke) | C++11 | 46 ms | 23804 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |