Submission #241111

# Submission time Handle Problem Language Result Execution time Memory
241111 2020-06-22T16:54:28 Z DavidDamian Lozinke (COCI17_lozinke) C++11
100 / 100
44 ms 23672 KB
#include <bits/stdc++.h>
using namespace std;
///Trie
///Determine the number of pairs that A can login as B
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) //Last hast to be different from actual string (that string can have the same substring
                                                                                    //but still the same person)
                trie[u].wordCount++;
            trie[u].last=id;
        }
    }
}
int query(string s) ///Return the number of other strings with the same substring than 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

lozinke.cpp: In function 'void Insert(std::__cxx11::string, int)':
lozinke.cpp:15:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int a=0;a<s.size();a++){
                 ~^~~~~~~~~
lozinke.cpp:17:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=a;i<s.size();i++){
                     ~^~~~~~~~~
lozinke.cpp: In function 'int query(std::__cxx11::string)':
lozinke.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0;i<s.size();i++){
                 ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 896 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 3200 KB Output is correct
9 Correct 11 ms 3324 KB Output is correct
10 Correct 21 ms 10748 KB Output is correct
11 Correct 15 ms 6012 KB Output is correct
12 Correct 44 ms 23672 KB Output is correct
13 Correct 19 ms 3836 KB Output is correct
14 Correct 32 ms 21368 KB Output is correct
15 Correct 41 ms 23408 KB Output is correct
16 Correct 21 ms 1788 KB Output is correct
17 Correct 17 ms 1532 KB Output is correct
18 Correct 19 ms 1532 KB Output is correct
19 Correct 33 ms 12152 KB Output is correct
20 Correct 14 ms 1660 KB Output is correct