Submission #138100

# Submission time Handle Problem Language Result Execution time Memory
138100 2019-07-29T10:43:49 Z Linca_Robert Lozinke (COCI17_lozinke) C++14
90 / 100
1000 ms 2904 KB
#include<bits/stdc++.h>
using namespace std;

int N, ans;
string arr[20005], str;
multiset<string> S;
vector<string> aux;

inline bool cmp( const string &a, const string &b ){
    if( a.size() == b.size() )
        return a < b;
    return a.size() < b.size();
}

int main(){
    cin >> N;
    for( int i = 1; i <= N; i++ )
        cin >> arr[i];

    sort( arr + 1, arr + N + 1, cmp );
    aux.resize( 115 );

    for( int i = 1; i <= N; i++ ){
        aux.clear();

        for( int p1 = 0; p1 < arr[i].length(); p1++ ){
            str.clear();
            for( int p2 = p1; p2 < arr[i].length(); p2++ ){
                str.push_back( arr[i][p2] );
                aux.push_back( str );
            }
        }

        sort( aux.begin(), aux.end() );
        aux.resize( distance( aux.begin(), unique( aux.begin(), aux.end() ) ) );

        for( int p = 0; p < aux.size(); p++ )
            ans += S.count( aux[p] );
        S.insert( arr[i] );
    }

    int nr = 1;
    for( int i = 2; i <= N; i++ ){
        if( arr[i] == arr[i - 1] )
            nr++;
        else
            nr = 1;
        ans += nr - 1;
    }

    cout << ans << "\n";
    return 0;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:26:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int p1 = 0; p1 < arr[i].length(); p1++ ){
                          ~~~^~~~~~~~~~~~~~~~~
lozinke.cpp:28:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for( int p2 = p1; p2 < arr[i].length(); p2++ ){
                               ~~~^~~~~~~~~~~~~~~~~
lozinke.cpp:37:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for( int p = 0; p < aux.size(); p++ )
                         ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1016 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 13 ms 1016 KB Output is correct
6 Correct 20 ms 1016 KB Output is correct
7 Correct 24 ms 1144 KB Output is correct
8 Correct 29 ms 1180 KB Output is correct
9 Correct 201 ms 1784 KB Output is correct
10 Correct 162 ms 1784 KB Output is correct
11 Correct 349 ms 2324 KB Output is correct
12 Correct 285 ms 2300 KB Output is correct
13 Correct 324 ms 2904 KB Output is correct
14 Correct 296 ms 2680 KB Output is correct
15 Correct 309 ms 2752 KB Output is correct
16 Correct 325 ms 2808 KB Output is correct
17 Execution timed out 1071 ms 2432 KB Time limit exceeded
18 Execution timed out 1077 ms 2304 KB Time limit exceeded
19 Correct 253 ms 2660 KB Output is correct
20 Correct 587 ms 2680 KB Output is correct