# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
85415 | 2018-11-19T20:04:00 Z | MohamedAhmed0 | Lozinke (COCI17_lozinke) | C++14 | 531 ms | 16728 KB |
/* Author : Mohamed Ahmed we should sort strings according to their size after that since that strings at most 10 letters so we can make map to store number of times that string occur and handle case if there's strings that equal and make another map to store number of times of substrings to handle case if there's two substrings equal and there's string equal to them so don't count it more than one and add to answer number of strings that same as current substring and after that increase number of times that current string appear */ #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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 256 KB | Output is correct |
2 | Correct | 2 ms | 500 KB | Output is correct |
3 | Correct | 3 ms | 548 KB | Output is correct |
4 | Correct | 3 ms | 600 KB | Output is correct |
5 | Correct | 13 ms | 892 KB | Output is correct |
6 | Correct | 25 ms | 892 KB | Output is correct |
7 | Correct | 34 ms | 1656 KB | Output is correct |
8 | Correct | 47 ms | 2468 KB | Output is correct |
9 | Correct | 111 ms | 2596 KB | Output is correct |
10 | Correct | 236 ms | 7724 KB | Output is correct |
11 | Correct | 177 ms | 7724 KB | Output is correct |
12 | Correct | 525 ms | 16728 KB | Output is correct |
13 | Correct | 357 ms | 16728 KB | Output is correct |
14 | Correct | 326 ms | 16728 KB | Output is correct |
15 | Correct | 531 ms | 16728 KB | Output is correct |
16 | Correct | 387 ms | 16728 KB | Output is correct |
17 | Correct | 92 ms | 16728 KB | Output is correct |
18 | Correct | 65 ms | 16728 KB | Output is correct |
19 | Correct | 338 ms | 16728 KB | Output is correct |
20 | Correct | 163 ms | 16728 KB | Output is correct |