답안 #152926

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152926 2019-09-10T14:13:45 Z phillip Lozinke (COCI17_lozinke) C++14
5 / 100
67 ms 24184 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++)
                     ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 7 ms 6520 KB Output isn't correct
2 Incorrect 7 ms 6520 KB Output isn't correct
3 Incorrect 9 ms 6648 KB Output isn't correct
4 Incorrect 8 ms 6776 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 13 ms 8568 KB Output isn't correct
9 Incorrect 28 ms 10104 KB Output isn't correct
10 Incorrect 36 ms 14840 KB Output isn't correct
11 Incorrect 40 ms 12792 KB Output isn't correct
12 Incorrect 57 ms 22748 KB Output isn't correct
13 Incorrect 61 ms 11512 KB Output isn't correct
14 Incorrect 56 ms 23160 KB Output isn't correct
15 Incorrect 67 ms 24184 KB Output isn't correct
16 Incorrect 66 ms 7288 KB Output isn't correct
17 Correct 32 ms 6776 KB Output is correct
18 Incorrect 31 ms 6776 KB Output isn't correct
19 Incorrect 57 ms 17272 KB Output isn't correct
20 Incorrect 47 ms 7160 KB Output isn't correct