Submission #863885

# Submission time Handle Problem Language Result Execution time Memory
863885 2023-10-21T10:34:13 Z edogawa_something Necklace (Subtask 1-3) (BOI19_necklace1) C++17
0 / 85
9 ms 19288 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vii;
typedef pair<ll,ll> pii;
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
const ll M=1002887;
const ll mod[5]={1000081,1000231,1000999,1002341,1002887};
const ll inf=1e18+10;
string s,t;
int b[5][M];
ll p[28][5],pp;
int main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin>>s>>t;
    p[0][0]=p[0][1]=p[0][2]=p[0][4]=p[0][3]=1;
    pp=3001;
    for(int i=1;i<28;i++){
        for(int j=0;j<5;j++){
            p[i][j]=p[i-1][j]*pp;
            p[i][j]%=mod[j];
        }
    }
    for(int i=0;i<s.size();i++){
        ll cur[5];
        cur[0]=cur[1]=cur[2]=cur[3]=cur[4]=0;
        bool chk=0;
        for(int j=i;j<inf;j++){
            j%=s.size();
            if(chk&&j==i)
            break;
            for(int k=0;k<5;k++)
            cur[k]+=p[s[j]-'a'+1][k],cur[k]%=mod[k],b[k][cur[k]]=max(b[k][cur[k]],i+1);
            chk=1;
        }
    }
    ll ans=0,ans1=0,ans2=0;
    for(int i=0;i<t.size();i++){
        ll cur[5];
        cur[0]=cur[1]=cur[2]=cur[3]=cur[4]=0;
        ll cnt=0;
        for(int j=i;j<inf;j++){
            cnt++;
            if(cnt==t.size()+1)
            break;
            j%=t.size();
            bool chk=1;
            map<ll,ll>mp;
            for(int k=0;k<5;k++){
            cur[k]+=p[t[j]-'a'+1][k],cur[k]%=mod[k];
            chk&=(b[k][cur[k]]>0);
            mp[b[k][cur[k]]]++;
            }
            if(chk){
            if(ans<cnt){
            ans=cnt;
            for(auto it:mp){
                if(it.S>=3){
                    ans1=it.F;
                }
            }
            ans2=i+1;
            }
            }
        }
    }
    cout<<ans<<'\n'<<ans1-1<<' '<<ans2-1;
}

Compilation message

necklace.cpp: In function 'int main()':
necklace.cpp:27:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
necklace.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=0;i<t.size();i++){
      |                 ~^~~~~~~~~
necklace.cpp:47:19: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |             if(cnt==t.size()+1)
      |                ~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19288 KB Output is correct
2 Correct 9 ms 18780 KB Output is correct
3 Correct 8 ms 15964 KB Output is correct
4 Incorrect 9 ms 17756 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19288 KB Output is correct
2 Correct 9 ms 18780 KB Output is correct
3 Correct 8 ms 15964 KB Output is correct
4 Incorrect 9 ms 17756 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19288 KB Output is correct
2 Correct 9 ms 18780 KB Output is correct
3 Correct 8 ms 15964 KB Output is correct
4 Incorrect 9 ms 17756 KB Output isn't correct
5 Halted 0 ms 0 KB -