# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
280454 | 2020-08-22T19:28:28 Z | Revo7 | Lozinke (COCI17_lozinke) | C++14 | 145 ms | 9264 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+9; 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; if(!vis[ha]){ ans+=cnt[ha]; vis[ha]=1; } } } ans--; } int main() { //setIO("threesum"); IOS 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1024 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 | 5 ms | 1152 KB | Output is correct |
6 | Correct | 5 ms | 1152 KB | Output is correct |
7 | Correct | 7 ms | 1536 KB | Output is correct |
8 | Correct | 10 ms | 1920 KB | Output is correct |
9 | Correct | 26 ms | 1920 KB | Output is correct |
10 | Correct | 52 ms | 4636 KB | Output is correct |
11 | Correct | 40 ms | 2820 KB | Output is correct |
12 | Incorrect | 138 ms | 9264 KB | Output isn't correct |
13 | Correct | 69 ms | 1820 KB | Output is correct |
14 | Incorrect | 111 ms | 8508 KB | Output isn't correct |
15 | Incorrect | 145 ms | 9148 KB | Output isn't correct |
16 | Correct | 81 ms | 1024 KB | Output is correct |
17 | Correct | 41 ms | 1016 KB | Output is correct |
18 | Correct | 30 ms | 1024 KB | Output is correct |
19 | Correct | 80 ms | 5020 KB | Output is correct |
20 | Correct | 42 ms | 1024 KB | Output is correct |