#include<bits/stdc++.h>
#define fi first
#define se second
using namespace std;
vector<pair<long long, string> > inp;
signed main(){
long long n;
cin >> n;
for(int i=0;i<n;i++){
string s;
cin >> s;
inp.push_back({s.size(),s});
}
long long ans=0;
sort(inp.begin(),inp.end());
for(int i=0;i<n;i++){
for(int j=0;j<i;j++){
if(inp[i].fi==inp[j].fi){
if(inp[i].se==inp[j].se){
//cout << inp[i].se<< " " << inp[j].se<<endl;
ans+=2;
}
}
else{
string a=inp[i].se;
string b=inp[j].se;
//cout << a << " " << b<< " " <<inp[i].fi-inp[j].fi+1<< " "<< ans<<" ";
for(int k=0;k<inp[i].fi-inp[j].fi+1;k++){
if(a[k]==b[0]){
long long test=0;
for(int l=0;l<inp[j].fi;l++){
if(a[k+l]!=b[l]){
test=1;
break;
}
}
if(test==0){
ans++;
break;
}
}
}
//cout << ans <<endl;
}
}
}
cout << ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
15 ms |
384 KB |
Output is correct |
6 |
Correct |
30 ms |
512 KB |
Output is correct |
7 |
Correct |
48 ms |
632 KB |
Output is correct |
8 |
Correct |
42 ms |
512 KB |
Output is correct |
9 |
Execution timed out |
1073 ms |
1084 KB |
Time limit exceeded |
10 |
Correct |
980 ms |
1084 KB |
Output is correct |
11 |
Execution timed out |
1059 ms |
1084 KB |
Time limit exceeded |
12 |
Execution timed out |
1071 ms |
1084 KB |
Time limit exceeded |
13 |
Execution timed out |
1062 ms |
1784 KB |
Time limit exceeded |
14 |
Execution timed out |
1083 ms |
1784 KB |
Time limit exceeded |
15 |
Execution timed out |
1080 ms |
1784 KB |
Time limit exceeded |
16 |
Execution timed out |
1061 ms |
1784 KB |
Time limit exceeded |
17 |
Execution timed out |
1050 ms |
1784 KB |
Time limit exceeded |
18 |
Execution timed out |
1056 ms |
1784 KB |
Time limit exceeded |
19 |
Execution timed out |
1078 ms |
1784 KB |
Time limit exceeded |
20 |
Execution timed out |
1080 ms |
1784 KB |
Time limit exceeded |