# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093222 | concaccon | Lozinke (COCI17_lozinke) | C++11 | 180 ms | 42832 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fol(i,a,b) for(int i=a;i>=b;i--)
#define base 31
#define ll long long
#define maxn 1000000
#define f first
#define s second
#define pb push_back
#define el cout << '\n'
#define pii pair<int,int>
const int inf=1e9+7;
const int mod=1e9+7;
using namespace std;
string inp[maxn];
int n;
namespace task2{
ll h[maxn][11],p[maxn];
ll get(int i,int l,int r){
return (h[i][r]-h[i][l-1]*p[(r-l+1)]%mod+mod)%mod;
}
void solve(){
p[0]=1;
fo(i,1,11) p[i]=p[i-1]*base%mod;
fo(i,1,n) {
int k=inp[i].size();
string s=' '+inp[i];
fo(j,1,k) h[i][j]=(h[i][j-1]*base+s[j]-'a'+1)%mod;
}
map<int,int > m;
fo(i,1,n){
fo(k,1,inp[i].size()){
string s=' '+inp[i];
map<int,int> ch;
fo(j,1,inp[i].size()-k+1) if(ch[get(i,j,j+k-1)]==0) m[get(i,j,j+k-1)]++,ch[get(i,j,j+k-1)]++;
}
}
int res=0;
fo(i,1,n) res+=m[get(i,1,inp[i].size())]-1;
cout <<res;
}
}
signed main(){
cin >> n;
fo(i,1,n) cin >> inp[i];
task2::solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |