# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
57937 |
2018-07-16T14:14:45 Z |
red1108 |
구간 성분 (KOI15_interval) |
C++17 |
|
300 ms |
1136 KB |
#include <iostream>
#include <unordered_map>
#include <string>
#include <algorithm>
using namespace std;
unordered_map<char,int> prime;
string a, b;
int cnt[27],atop,btop,h[27];
struct DATA{
int value;
int s, e;
}ah[2500000],bh[2500000];
int asum[30][1600],bsum[30][1600];
bool cmp(DATA A, DATA B)
{
return A.value<B.value;
}
void init()
{
h[0]=1;
h[1]=1;
h[2]=1;
h[3]=1;
h[4]=2;
h[5]=1;
h[6]=2;
h[7]=1;
h[8]=1;
h[9]=1;
h[10]=1;
h[11]=2;
h[12]=2;
h[13]=1;
h[14]=1;
h[15]=1;
h[16]=1;
h[17]=1;
h[18]=1;
h[19]=1;
h[20]=1;
h[21]=2;
h[22]=2;
h[23]=1;
h[24]=2;
h[25]=1;
}
int main()
{
init();
ios_base::sync_with_stdio(false);
cin.tie(0);
int i, j,l,hashing,k,flag,x,get=0,kc;
cin>>a;
cin>>b;
for(i=0;i<26;i++)
{
for(j=0;j<a.size();j++){asum[i][j]=a[j]-'a'==i?asum[i][j-1]+1:asum[i][j-1];}
}
for(i=0;i<26;i++)
{
for(j=0;j<b.size();j++){bsum[i][j]=b[j]-'a'==i?bsum[i][j-1]+1:bsum[i][j-1];}
}
l=min(a.size(),b.size());
for(i=l;i>=1;i--)
{
hashing=0;
atop=0;
btop=0;
for(j=0;j<i;j++) {hashing+=h[a[j]-'a'];}
for(j=i-1;j<a.size();j++)
{
ah[++atop].value=hashing;
ah[atop].s=j-i+1;
ah[atop].e=j;
hashing+=h[a[j+1]-'a'];
hashing-=h[a[j-i+1]-'a'];
}
hashing=0;
for(j=0;j<i;j++) {hashing+=h[b[j]-'a'];}
for(j=i-1;j<b.size();j++)
{
bh[++btop].value=hashing;
bh[btop].s=j-i+1;
bh[btop].e=j;
hashing+=h[b[j+1]-'a'];
hashing-=h[b[j-i+1]-'a'];
}
sort(ah+1,ah+atop+1,cmp);
sort(bh+1,bh+btop+1,cmp);
k=1;
for(j=1;j<=atop;j++)
{
while(bh[k].value<ah[j].value&&k<b.size()) k++;
if(k>=b.size()) break;
if(bh[k].value>ah[j].value) continue;
kc=k;
while(bh[k].value==ah[j].value&&k<b.size())
{
flag=1;
for(x=0;x<26;x++)
{
if(asum[x][ah[j].e]-asum[x][ah[j].s-1]!=bsum[x][bh[k].e]-bsum[x][bh[k].s-1]){flag=0;break;}
}
if(flag)
{
get=1;
break;
}
k++;
}
if(get)
{
printf("%d\n", i);
return 0;
}
if(ah[j].value==ah[j+1].value) k=kc;
}
}
printf("0");
}
Compilation message
interval.cpp: In function 'int main()':
interval.cpp:57:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<a.size();j++){asum[i][j]=a[j]-'a'==i?asum[i][j-1]+1:asum[i][j-1];}
~^~~~~~~~~
interval.cpp:61:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=0;j<b.size();j++){bsum[i][j]=b[j]-'a'==i?bsum[i][j-1]+1:bsum[i][j-1];}
~^~~~~~~~~
interval.cpp:70:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=i-1;j<a.size();j++)
~^~~~~~~~~
interval.cpp:80:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(j=i-1;j<b.size();j++)
~^~~~~~~~~
interval.cpp:93:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(bh[k].value<ah[j].value&&k<b.size()) k++;
~^~~~~~~~~
interval.cpp:94:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(k>=b.size()) break;
~^~~~~~~~~~
interval.cpp:97:46: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(bh[k].value==ah[j].value&&k<b.size())
~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
2 ms |
616 KB |
Output is correct |
3 |
Correct |
2 ms |
616 KB |
Output is correct |
4 |
Correct |
4 ms |
648 KB |
Output is correct |
5 |
Correct |
3 ms |
648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
852 KB |
Output is correct |
2 |
Correct |
13 ms |
852 KB |
Output is correct |
3 |
Correct |
2 ms |
852 KB |
Output is correct |
4 |
Correct |
3 ms |
880 KB |
Output is correct |
5 |
Correct |
29 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
108 ms |
952 KB |
Output is correct |
2 |
Correct |
112 ms |
952 KB |
Output is correct |
3 |
Correct |
116 ms |
992 KB |
Output is correct |
4 |
Correct |
129 ms |
1000 KB |
Output is correct |
5 |
Correct |
129 ms |
1000 KB |
Output is correct |
6 |
Correct |
97 ms |
1116 KB |
Output is correct |
7 |
Correct |
113 ms |
1116 KB |
Output is correct |
8 |
Correct |
123 ms |
1116 KB |
Output is correct |
9 |
Correct |
137 ms |
1116 KB |
Output is correct |
10 |
Correct |
121 ms |
1116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
190 ms |
1136 KB |
Output is correct |
2 |
Correct |
300 ms |
1136 KB |
Output is correct |
3 |
Correct |
263 ms |
1136 KB |
Output is correct |
4 |
Correct |
33 ms |
1136 KB |
Output is correct |
5 |
Correct |
285 ms |
1136 KB |
Output is correct |