# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
280445 | 2020-08-22T19:17:56 Z | Revo7 | Lozinke (COCI17_lozinke) | C++14 | 158 ms | 9408 KB |
#include <bits/stdc++.h> #define ll long long #define pb push_back #define left 2*i+1 #define righ 2*i+2 #define mid (l+r)/2 #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll maxn=2e4+100; const ll mod=1e9+7; const ll base=27; ll n; string s[maxn]; unordered_map<ll,ll>cnt; ll ans=0; unordered_map<ll,bool>vis; void solve(ll i){ vis.clear(); for(ll l=0;l<s[i].size();l++){ ll ha=0; for(ll r=l;r<s[i].size();r++){ ha=ha*base%mod; ha=(ha+(s[i][r]-'a'+1)%mod)%mod; if(!vis[ha]){ ans+=cnt[ha]; vis[ha]=1; } } } ans--; } int main() { //setIO("threesum"); cin>>n; for(ll i=0;i<n;i++)cin>>s[i]; for(ll i=0;i<n;i++){ ll ha=0; for(ll j=0;j<s[i].size();j++){ ha=ha*base%mod; ha=(ha+(s[i][j]-'a'+1))%mod; } cnt[ha]++; } for(ll i=0;i<n;i++)solve(i); cout<<ans<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 896 KB | Output is correct |
2 | Correct | 1 ms | 1024 KB | Output is correct |
3 | Correct | 1 ms | 1024 KB | Output is correct |
4 | Correct | 2 ms | 1024 KB | Output is correct |
5 | Correct | 4 ms | 1152 KB | Output is correct |
6 | Correct | 6 ms | 1152 KB | Output is correct |
7 | Correct | 7 ms | 1536 KB | Output is correct |
8 | Correct | 11 ms | 2048 KB | Output is correct |
9 | Incorrect | 27 ms | 1912 KB | Output isn't correct |
10 | Incorrect | 60 ms | 4764 KB | Output isn't correct |
11 | Correct | 44 ms | 2908 KB | Output is correct |
12 | Incorrect | 158 ms | 9408 KB | Output isn't correct |
13 | Correct | 75 ms | 2040 KB | Output is correct |
14 | Incorrect | 135 ms | 8764 KB | Output isn't correct |
15 | Incorrect | 150 ms | 9256 KB | Output isn't correct |
16 | Correct | 100 ms | 1296 KB | Output is correct |
17 | Correct | 60 ms | 1152 KB | Output is correct |
18 | Correct | 38 ms | 1152 KB | Output is correct |
19 | Correct | 99 ms | 5148 KB | Output is correct |
20 | Correct | 50 ms | 1152 KB | Output is correct |