# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1093202 | concaccon | Lozinke (COCI17_lozinke) | C++11 | 57 ms | 64436 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 task1{
int h[10][maxn],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;
}
int res=0;
fo(i,1,n){
fo(j,1,n)if(i!=j && inp[i].size()<=inp[j].size()){
fo(k,0,inp[j].size()-inp[i].size()+1) {
//cout <<get(i,1,inp[i].size())<< ' '<<get(j,k+1,k+inp[i].size()),el;
if(get(i,1,inp[i].size())==get(j,k+1,k+inp[i].size())){
res++;
break;
}
}
}
}
cout <<res;
}
}
namespace task2{
int h[10][maxn],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];
if(n<2000) task1::solve();
else task2::solve();
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |