#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define yes "YES"
#define no "NO"
#define bigg INT_MAX
#define debug(x) cout<<(#x)<<" = " <<x<<endl;
#define all(x) x.begin(),x.end()
#define sz size()
#define nn '\n'
#define mms(x,y) memset(x,y,sizeof(x))
#define forr(i,j,n) for (int i=j; i<n; i++)
#define forn(i,j,n) for (int i=j; i>n; i--)
#define fi first
#define se second
#define la "LA"
#define cinn(x,y) for(int i=0; i<y; i++) cin>>x[i];
#define pii pair<int,int>
signed main()
{
// #ifndef LOCAL
// freopen("helpcross.in","r",stdin);
// freopen("helpcross.out","w", stdout);
// #endif
fast
int n;
cin>>n;
string a[n];
unordered_map<string,int> m;
//unordered_map<string,bool> b;
forr(i,0,n)
{
cin>>a[i];
m[a[i]]++;
// b[a[i]]=1;
}
int ans=0;
forr(k,0,n)
{
string s=a[k];
int w=s.sz;
//unordered_map<string,bool> cb=b;
map<string, bool> vis;
forr(j,0,w)
{
string cur="";
forr(i,j,w)
{
cur+=s[i];
//cout<<k<<' '<<cur<<endl;
// if (cb[cur])
if(!vis[cur]){ ans+=m[cur];
vis[cur]=1;}
//cb[cur]=0;
}
// cout<<k<<' '<<cur<<endl;
}
}
cout<<ans-n;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
604 KB |
Output is correct |
6 |
Correct |
8 ms |
604 KB |
Output is correct |
7 |
Correct |
10 ms |
1372 KB |
Output is correct |
8 |
Correct |
16 ms |
2232 KB |
Output is correct |
9 |
Correct |
43 ms |
2432 KB |
Output is correct |
10 |
Correct |
82 ms |
8084 KB |
Output is correct |
11 |
Correct |
69 ms |
4508 KB |
Output is correct |
12 |
Correct |
210 ms |
16352 KB |
Output is correct |
13 |
Correct |
132 ms |
2732 KB |
Output is correct |
14 |
Correct |
122 ms |
15824 KB |
Output is correct |
15 |
Correct |
186 ms |
16028 KB |
Output is correct |
16 |
Correct |
145 ms |
1116 KB |
Output is correct |
17 |
Correct |
42 ms |
860 KB |
Output is correct |
18 |
Correct |
31 ms |
860 KB |
Output is correct |
19 |
Correct |
122 ms |
8356 KB |
Output is correct |
20 |
Correct |
80 ms |
1192 KB |
Output is correct |