#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
#define Asize 10
int N,M;
int a[1510],b[1510],tmp[1510];
char s[1510];
struct data{
int cnt;
long long a[Asize];
bool operator<(const data x)const{
int i;
if(x.cnt != cnt) return cnt < x.cnt;
for(i=0; i<Asize; i++){
if(x.a[i] != a[i]) return a[i] < x.a[i];
}
return false;
}
};
struct data2{
long long a[26];
}cnt1[1510],cnt2[1510];
data t;
map<data,bool> Map;
long long square[10];
void setting(){
int i,j,k;
square[0] = 1;
for(i=1; i<=3; i++) square[i] = square[i-1]*1501;
scanf("%s",s);
N = strlen(s);
for(i=1; i<=N; i++) a[i] = s[i-1]-'a';
scanf("%s",s);
M = strlen(s);
for(i=1; i<=M; i++) b[i] = s[i-1]-'a';
if(N > M){
for(i=1; i<=N; i++) tmp[i] = a[i];
for(i=1; i<=M; i++) a[i] = b[i];
for(i=1; i<=N; i++) b[i] = tmp[i];
swap(N,M);
}
for(i=1; i<=N; i++){
for(j=0; j<26; j++) cnt1[i].a[j] = cnt1[i-1].a[j];
cnt1[i].a[a[i]]++;
}
for(i=1; i<=M; i++){
for(j=0; j<26; j++) cnt2[i].a[j] = cnt2[i-1].a[j];
cnt2[i].a[b[i]]++;
}
for(i=1; i<=M; i++){
for(j=i; j<=M; j++){
for(k=0; k<Asize; k++) t.a[k] = 0;
for(k=0; k<26; k++) t.a[k/3] += ((cnt2[j].a[k]-cnt2[i-1].a[k])*square[k%3]);
t.cnt = j-i+1;
Map[t] = true;
}
}
}
int main(){
int i,j,k;
//freopen("input.txt","r",stdin);
setting();
for(i=N-1; i>=0; i--){
for(j=1; j+i<=N; j++){
for(k=0; k<Asize; k++) t.a[k] = 0;
for(k=0; k<26; k++) t.a[k/3] += ((cnt1[j+i].a[k]-cnt1[j-1].a[k])*square[k%3]);
t.cnt = i+1;
if(Map.find(t) != Map.end()){
printf("%d",i+1);
return 0;
}
}
}
printf("0");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1852 KB |
Output is correct |
2 |
Correct |
0 ms |
1852 KB |
Output is correct |
3 |
Correct |
1 ms |
1852 KB |
Output is correct |
4 |
Correct |
4 ms |
2512 KB |
Output is correct |
5 |
Correct |
3 ms |
2380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
131 ms |
18616 KB |
Output is correct |
2 |
Correct |
110 ms |
15316 KB |
Output is correct |
3 |
Correct |
39 ms |
2908 KB |
Output is correct |
4 |
Correct |
25 ms |
1852 KB |
Output is correct |
5 |
Correct |
137 ms |
17692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
609 ms |
66400 KB |
Output is correct |
2 |
Correct |
629 ms |
68776 KB |
Output is correct |
3 |
Correct |
594 ms |
67984 KB |
Output is correct |
4 |
Correct |
605 ms |
66400 KB |
Output is correct |
5 |
Correct |
628 ms |
68512 KB |
Output is correct |
6 |
Correct |
602 ms |
66796 KB |
Output is correct |
7 |
Correct |
599 ms |
68512 KB |
Output is correct |
8 |
Correct |
630 ms |
68644 KB |
Output is correct |
9 |
Correct |
603 ms |
68776 KB |
Output is correct |
10 |
Correct |
604 ms |
68380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
456 ms |
25612 KB |
Output is correct |
2 |
Memory limit exceeded |
886 ms |
131072 KB |
Memory limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |