Submission #475207

# Submission time Handle Problem Language Result Execution time Memory
475207 2021-09-21T12:59:12 Z MohamedAhmed04 Lozinke (COCI17_lozinke) C++14
100 / 100
442 ms 16472 KB
#include <bits/stdc++.h>
 
using namespace std;
 
bool cmp(string &s , string &s1)
{
    return s.size() < s1.size() ;
}
 
int main()
{
    int n ;
    cin>>n ;
    string arr[n] ;
    for(int i = 0 ; i < n ; ++i)
        cin>>arr[i] ;
    sort(arr , arr + n , cmp) ;
    long long ans = 0ll ;
    map<string , int>mp ;
    for(int i = 0 ; i < n ; ++i)
    {
        string s = arr[i] ;
        map<string , int>mp2 ;
        ans += mp[s] ;
        for(int j = 0 ; j < s.size() ; ++j)
        {
            string s1 = "" ;
            for(int k = j ; k < s.size() ; ++k)
            {
                 s1 += s[k] ;
                 if(mp2[s1] != 1)
                    ans += mp[s1] * 1ll ;
                 mp2[s1] = 1 ;
            }
        }
        mp[s]++;
    }
    return cout<<ans , 0 ;
}

Compilation message

lozinke.cpp: In function 'int main()':
lozinke.cpp:25:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for(int j = 0 ; j < s.size() ; ++j)
      |                         ~~^~~~~~~~~~
lozinke.cpp:28:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |             for(int k = j ; k < s.size() ; ++k)
      |                             ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 10 ms 604 KB Output is correct
6 Correct 17 ms 588 KB Output is correct
7 Correct 22 ms 1408 KB Output is correct
8 Correct 43 ms 2248 KB Output is correct
9 Correct 104 ms 2380 KB Output is correct
10 Correct 192 ms 7456 KB Output is correct
11 Correct 147 ms 4252 KB Output is correct
12 Correct 442 ms 16472 KB Output is correct
13 Correct 299 ms 2764 KB Output is correct
14 Correct 300 ms 14964 KB Output is correct
15 Correct 429 ms 16452 KB Output is correct
16 Correct 326 ms 1264 KB Output is correct
17 Correct 93 ms 1100 KB Output is correct
18 Correct 64 ms 972 KB Output is correct
19 Correct 291 ms 8616 KB Output is correct
20 Correct 165 ms 1184 KB Output is correct