# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
152769 | phillip | Lozinke (COCI17_lozinke) | C++14 | 54 ms | 19860 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
long long the,n;
string s[100004];
struct trie
{
int en=0,cnt=0;
trie *a[27]={0};
void inse(int x,int y)
{
if (y==s[x].size())
{
en++;
cnt++;
return;
}
int ind=s[x][y]-'a';
if (a[ind]==0) a[ind]=new trie;
a[ind]->inse(x,y+1);
}
void ans(int x,int y)
{
the+=en;
en=0;
if (y==s[x].size()) return ;
if (a[s[x][y]-'a']!=0) a[s[x][y]-'a']->ans(x,y+1);
return ;
}
void rep(int x,int y)
{
en=cnt;
if (y==s[x].size()) return ;
if (a[s[x][y]-'a']!=0) a[s[x][y]-'a']->rep(x,y+1);
return ;
}
};
trie tr;
int main()
{
cin>>n;
for (int i=0;i<n;i++)
{
cin>>s[i];
tr.inse(i,0);
}
for (int i=0;i<n;i++)
{
for (int j=0;j<s[i].size();j++) tr.ans(i,j);
for (int j=0;j<s[i].size();j++) tr.rep(i,j);
}
cout<<the-n;
return 0;
}
//Sent from Mail for Windows 10
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |