답안 #152769

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152769 2019-09-09T12:30:04 Z phillip Lozinke (COCI17_lozinke) C++14
100 / 100
54 ms 19860 KB
#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

Compilation message

lozinke.cpp: In member function 'void trie::inse(int, int)':
lozinke.cpp:13:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (y==s[x].size())
             ~^~~~~~~~~~~~~
lozinke.cpp: In member function 'void trie::ans(int, int)':
lozinke.cpp:27:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (y==s[x].size()) return ;
             ~^~~~~~~~~~~~~
lozinke.cpp: In member function 'void trie::rep(int, int)':
lozinke.cpp:34:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (y==s[x].size()) return ;
             ~^~~~~~~~~~~~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:50:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j=0;j<s[i].size();j++) tr.ans(i,j);
                          ~^~~~~~~~~~~~
lozinke.cpp:51:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for (int j=0;j<s[i].size();j++) tr.rep(i,j);
                          ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3448 KB Output is correct
2 Correct 6 ms 3448 KB Output is correct
3 Correct 5 ms 3448 KB Output is correct
4 Correct 6 ms 3576 KB Output is correct
5 Correct 7 ms 4136 KB Output is correct
6 Correct 8 ms 4088 KB Output is correct
7 Correct 9 ms 4728 KB Output is correct
8 Correct 11 ms 5240 KB Output is correct
9 Correct 19 ms 6776 KB Output is correct
10 Correct 27 ms 11128 KB Output is correct
11 Correct 26 ms 9208 KB Output is correct
12 Correct 47 ms 18424 KB Output is correct
13 Correct 39 ms 8056 KB Output is correct
14 Correct 44 ms 19064 KB Output is correct
15 Correct 54 ms 19860 KB Output is correct
16 Correct 38 ms 4212 KB Output is correct
17 Correct 39 ms 3832 KB Output is correct
18 Correct 31 ms 3632 KB Output is correct
19 Correct 43 ms 13432 KB Output is correct
20 Correct 28 ms 3960 KB Output is correct