Submission #48817

# Submission time Handle Problem Language Result Execution time Memory
48817 2018-05-19T04:56:04 Z leehosu01 구간 성분 (KOI15_interval) C++17
100 / 100
744 ms 1028 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string A,B;
int im[30];
pair<ll,ll> H()
{
    ll H1=0,H2=0,p1=10067,p2=100000007,n1=65,n2=117;
    for(int i=0;i<30;i++)
        H1=(H1*n1+im[i])%p1,H2=(H2*n2+im[i])%p2;
    return {H1,H2};
}
bool Sh(ll len)
{

    for(int i=0;i<30;i++)im[i]=0;
    set<pair<ll,ll> > inA;
    int i;
    for(i=0;i<len;i++)im[A[i]-'a']++;
    inA.insert(H());
    for(i=len;i<A.size();i++)
    {
        im[A[i]-'a']++;
        im[A[i-len]-'a']--;
        inA.insert(H());
    }
    for(int i=0;i<30;i++)im[i]=0;
    for(i=0;i<len;i++)im[B[i]-'a']++;
        if(inA.find(H())!=inA.end())return 1;
    for(i=len;i<B.size();i++)
    {
        im[B[i]-'a']++;
        im[B[i-len]-'a']--;
        if(inA.find(H())!=inA.end())return 1;
    }
    return 0;
}
int main()
{
    cin>>A>>B;
    int l=1,m,lm=0,r=min((int)A.size(),(int)B.size());
    for(m=r;m&&!Sh(m);m--);
  /*  while(l<r)
    {

        m=l+r>>1;
        if(Sh(m))lm=m,l=m+1;
        else r=m-1;
    }*/
    cout<<m;
}

Compilation message

interval.cpp: In function 'bool Sh(ll)':
interval.cpp:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=len;i<A.size();i++)
               ~^~~~~~~~~
interval.cpp:30:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=len;i<B.size();i++)
               ~^~~~~~~~~
interval.cpp: In function 'int main()':
interval.cpp:41:9: warning: unused variable 'l' [-Wunused-variable]
     int l=1,m,lm=0,r=min((int)A.size(),(int)B.size());
         ^
interval.cpp:41:15: warning: unused variable 'lm' [-Wunused-variable]
     int l=1,m,lm=0,r=min((int)A.size(),(int)B.size());
               ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 5 ms 488 KB Output is correct
5 Correct 5 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 692 KB Output is correct
2 Correct 47 ms 692 KB Output is correct
3 Correct 3 ms 692 KB Output is correct
4 Correct 2 ms 692 KB Output is correct
5 Correct 84 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 316 ms 748 KB Output is correct
2 Correct 307 ms 792 KB Output is correct
3 Correct 333 ms 792 KB Output is correct
4 Correct 331 ms 792 KB Output is correct
5 Correct 336 ms 792 KB Output is correct
6 Correct 332 ms 792 KB Output is correct
7 Correct 323 ms 792 KB Output is correct
8 Correct 323 ms 800 KB Output is correct
9 Correct 347 ms 800 KB Output is correct
10 Correct 324 ms 1028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 1028 KB Output is correct
2 Correct 700 ms 1028 KB Output is correct
3 Correct 627 ms 1028 KB Output is correct
4 Correct 31 ms 1028 KB Output is correct
5 Correct 744 ms 1028 KB Output is correct