Submission #152929

# Submission time Handle Problem Language Result Execution time Memory
152929 2019-09-10T14:15:29 Z phillip Lozinke (COCI17_lozinke) C++14
10 / 100
67 ms 23900 KB

#include <bits/stdc++.h>
using namespace std;

struct Trie{

    int cnt,ed,ored ;
    Trie *a[29];

    Trie(){
        cnt = 0;
        ed=0;
        ored=0;
        for(int i=0;i<29;i++)
            a[i] = 0;
    }
};

void insert(Trie *node,int pos,string s){
        node->cnt++;
        if(pos == s.size())
            return ;

        int num = s[pos]-'a';
        if(node->a[num] == 0)
            node->a[num] = new Trie();

        insert(node->a[num],pos+1,s);
        if(pos == s.size()-1)
        {
            node->ored++;
            node->ed++;
        }
    }
int ret=0;
void query(Trie *node,int pos,string s){

        if(pos == s.size())
            return;
         int num = s[pos]-'a';
         if(node->a[num] == 0)
            return;
         ret+=node->ed;
         node->ed=0;
         query(node->a[num],pos+1,s);
}
void rb(Trie *node,int pos,string s){

        if(pos == s.size())
            return;
         int num = s[pos]-'a';
         if(node->a[num] == 0)
            return;
         node->ed=node->ored;
         rb(node->a[num],pos+1,s);
}

Trie *root = new Trie();
bool cmp(string a,string b)
{
    if(a.size()<b.size())return true;
    return false;
}
int n;
string s[200009];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)cin>>s[i];
    //
    // cout<<query(root,0,a);
    sort(s,s+n,cmp);
    int ans=0,sum=0,s2;
    for(int i=0;i<n;i++)
    {
        sum=1;
        while(s[i]==s[i+1])
        {
            sum++;
            i++;
        }
        //cout<<sum<<"\n";
        ans+=(sum-1)*sum;
        int ls=s[i].size();
        s2=0;
        for(int j=0;j<s[i].size();j++)
        {
            ret=0;
            query(root,0,s[i].substr(j,ls));
            s2+=ret;
        }
        for(int j=0;j<s[i].size();j++)
        {
            ret=0;
            rb(root,0,s[i].substr(j,ls));
            s2+=ret;
        }
        ans+=s2*(sum);
        for(int j=0;j<sum;j++)insert(root,0,s[i]);
    }
    cout<<ans;
}

Compilation message

lozinke.cpp: In function 'void insert(Trie*, int, std::__cxx11::string)':
lozinke.cpp:22:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pos == s.size())
            ~~~~^~~~~~~~~~~
lozinke.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pos == s.size()-1)
            ~~~~^~~~~~~~~~~~~
lozinke.cpp: In function 'void query(Trie*, int, std::__cxx11::string)':
lozinke.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pos == s.size())
            ~~~~^~~~~~~~~~~
lozinke.cpp: In function 'void rb(Trie*, int, std::__cxx11::string)':
lozinke.cpp:50:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(pos == s.size())
            ~~~~^~~~~~~~~~~
lozinke.cpp: In function 'int main()':
lozinke.cpp:87:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<s[i].size();j++)
                     ~^~~~~~~~~~~~
lozinke.cpp:93:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<s[i].size();j++)
                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 6520 KB Output isn't correct
2 Incorrect 9 ms 6648 KB Output isn't correct
3 Incorrect 8 ms 6648 KB Output isn't correct
4 Incorrect 8 ms 6648 KB Output isn't correct
5 Incorrect 10 ms 7160 KB Output isn't correct
6 Incorrect 14 ms 7288 KB Output isn't correct
7 Incorrect 12 ms 8056 KB Output isn't correct
8 Incorrect 13 ms 8568 KB Output isn't correct
9 Incorrect 28 ms 10104 KB Output isn't correct
10 Incorrect 36 ms 14712 KB Output isn't correct
11 Incorrect 39 ms 12664 KB Output isn't correct
12 Incorrect 56 ms 22520 KB Output isn't correct
13 Incorrect 61 ms 11384 KB Output isn't correct
14 Incorrect 66 ms 23076 KB Output isn't correct
15 Incorrect 66 ms 23900 KB Output isn't correct
16 Incorrect 67 ms 7164 KB Output isn't correct
17 Correct 32 ms 6620 KB Output is correct
18 Correct 31 ms 6520 KB Output is correct
19 Incorrect 57 ms 17052 KB Output isn't correct
20 Incorrect 50 ms 7032 KB Output isn't correct