Submission #152927

# Submission time Handle Problem Language Result Execution time Memory
152927 2019-09-10T14:14:03 Z phillip Lozinke (COCI17_lozinke) C++14
5 / 100
67 ms 23928 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;
         query(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 7 ms 6648 KB Output isn't correct
3 Incorrect 7 ms 6648 KB Output isn't correct
4 Incorrect 8 ms 6648 KB Output isn't correct
5 Incorrect 12 ms 7160 KB Output isn't correct
6 Incorrect 11 ms 7288 KB Output isn't correct
7 Incorrect 12 ms 8056 KB Output isn't correct
8 Incorrect 5 ms 8572 KB Output isn't correct
9 Incorrect 28 ms 9976 KB Output isn't correct
10 Incorrect 41 ms 14712 KB Output isn't correct
11 Incorrect 41 ms 12700 KB Output isn't correct
12 Incorrect 59 ms 22548 KB Output isn't correct
13 Incorrect 62 ms 11480 KB Output isn't correct
14 Incorrect 57 ms 23084 KB Output isn't correct
15 Incorrect 67 ms 23928 KB Output isn't correct
16 Incorrect 66 ms 7160 KB Output isn't correct
17 Correct 34 ms 6652 KB Output is correct
18 Incorrect 31 ms 6520 KB Output isn't correct
19 Incorrect 57 ms 17144 KB Output isn't correct
20 Incorrect 47 ms 7032 KB Output isn't correct