# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26677 | TAMREF | 구간 성분 (KOI15_interval) | C++11 | 276 ms | 2160 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>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll pow1500[26]={1};
char A[1505], B[1505];
int N,M;
set<ll> S;
void init(){
for(int i=1;i<26;i++) pow1500[i]=(pow1500[i-1]*26)%mod;
fgets(A,1502,stdin); N=strlen(A); A[--N]=0;
fgets(B,1502,stdin); M=strlen(B); B[--M]=0;
for(int i=0;i<N;i++) A[i]&=15;
for(int i=0;i<M;i++) B[i]&=15;
}
bool pro(int x){
S.clear();
ll H=0;
for(int i=0;i<x;i++) H=(H+pow1500[A[i]-1])%mod;
S.insert(H);
for(int i=x;i<N;i++){
H=(((H+pow1500[A[i]-1])%mod-pow1500[A[i-x]-1])%mod+mod)%mod;
S.insert(H);
}
H=0;
for(int i=0;i<x;i++) H=(H+pow1500[B[i]-1])%mod;
if(S.find(H)!=S.end()) return true;
for(int i=x;i<M;i++){
H=(((H+pow1500[B[i]-1])%mod-pow1500[B[i-x]-1])%mod+mod)%mod;
if(S.find(H)!=S.end()) return true;
}
return false;
}
int main(){
init();
int ans=0, x=min(N,M);
for(int i=1;i<=x;i++) if(pro(i)) ans=max(ans,i);
printf("%d\n",ans);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |