답안 #138102

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
138102 2019-07-29T10:47:29 Z Linca_Robert Lozinke (COCI17_lozinke) C++14
100 / 100
234 ms 2300 KB
#include<bits/stdc++.h>
using namespace std;

int N, ans;
string arr[20005], str;
unordered_map<string, int> 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++ )
            if( S.find( aux[p] ) != S.end() )
                ans += S[ aux[p] ];

        if( S.find( arr[i] ) == S.end() )
            S[ arr[i] ] = 1;
        else
            S[ 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++ )
                         ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 888 KB Output is correct
2 Correct 3 ms 888 KB Output is correct
3 Correct 3 ms 888 KB Output is correct
4 Correct 3 ms 1016 KB Output is correct
5 Correct 10 ms 1016 KB Output is correct
6 Correct 15 ms 1016 KB Output is correct
7 Correct 17 ms 1148 KB Output is correct
8 Correct 20 ms 1016 KB Output is correct
9 Correct 71 ms 1400 KB Output is correct
10 Correct 95 ms 1556 KB Output is correct
11 Correct 105 ms 1784 KB Output is correct
12 Correct 171 ms 1888 KB Output is correct
13 Correct 204 ms 2264 KB Output is correct
14 Correct 139 ms 2300 KB Output is correct
15 Correct 182 ms 2296 KB Output is correct
16 Correct 202 ms 1272 KB Output is correct
17 Correct 138 ms 1272 KB Output is correct
18 Correct 111 ms 1144 KB Output is correct
19 Correct 234 ms 2040 KB Output is correct
20 Correct 122 ms 1272 KB Output is correct