Submission #141684

# Submission time Handle Problem Language Result Execution time Memory
141684 2019-08-08T21:34:38 Z Mihnea Lozinke (COCI17_lozinke) C++14
100 / 100
270 ms 2296 KB
#include<iostream>
#include<map>
#include<string>
#include<set>
#include<algorithm>
using namespace std;
int n,s;
string st[20010],sc;
set <string> a;
map <string,int> b;

int cmp(string a,string b) {
    if (a.size()!=b.size())
        return a.size()<b.size();
    else
        return a<b;
}

int main(){
    cin>>n;
    int s=0;
    for(int i=1;i<=n;i++)
        cin>>st[i];
    sort(st+1,st+n+1,cmp);
    for(int i=1;i<=n;i++) {
        a.clear();
        for(int j=0;j<st[i].size();j++) {
            sc.erase( sc.begin(),sc.end() );
            for(int k=j;k<st[i].size();k++) {
                sc.push_back(st[i][k]);
                a.insert(sc);
            }
        }
        for(set<string>::iterator it=a.begin();it!=a.end();it++) {
            if (b.find(*it)!=b.end())
                s+=b[*it];
        }
        if(b.find(st[i])==b.end())
            b[st[i]]=1;
        else
            b[st[i]]++;
    }
    int L=1;
    for(int i=2;i<=n;i++) {
        if(st[i]==st[i-1])
            L++;
        else
            L=1;
        s+=L-1;
    }
    cout<<s;
    return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:27:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<st[i].size();j++) {
                     ~^~~~~~~~~~~~~
lozinke.cpp:29:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k=j;k<st[i].size();k++) {
                         ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 888 KB Output is correct
2 Correct 3 ms 1016 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 4 ms 1016 KB Output is correct
5 Correct 12 ms 1016 KB Output is correct
6 Correct 18 ms 1016 KB Output is correct
7 Correct 21 ms 1016 KB Output is correct
8 Correct 25 ms 1144 KB Output is correct
9 Correct 96 ms 1528 KB Output is correct
10 Correct 128 ms 1528 KB Output is correct
11 Correct 154 ms 1760 KB Output is correct
12 Correct 251 ms 1948 KB Output is correct
13 Correct 250 ms 2168 KB Output is correct
14 Correct 211 ms 2296 KB Output is correct
15 Correct 270 ms 2204 KB Output is correct
16 Correct 205 ms 1468 KB Output is correct
17 Correct 80 ms 1144 KB Output is correct
18 Correct 72 ms 1016 KB Output is correct
19 Correct 219 ms 2112 KB Output is correct
20 Correct 134 ms 1440 KB Output is correct