Submission #1062818

# Submission time Handle Problem Language Result Execution time Memory
1062818 2024-08-17T11:01:11 Z DucNguyen2007 Necklace (Subtask 1-3) (BOI19_necklace1) C++14
85 / 85
137 ms 2652 KB
#include<bits/stdc++.h>
using namespace std;
const int maxN=1e6+5;
#define ll long long
#define ben(x) x.begin(),x.end()
string s,t;
ll ans[3],n,m,p1[maxN+1],p2[maxN+1];
void calc(string s,ll p[])
{
    ll n=s.length();
    p[0]=0;
    for(int i=1;i<n;i++)
    {
 
        ll j=p[i-1];
        while(j>0&&s[i]!=s[j])
        {
            j=p[j-1];
        }
        if(s[i]==s[j])
        {
            j++;
        }
        p[i]=j;
    }
}
void solve(string s,string t,bool rev)
{
    string t_rev=t;
    reverse(ben(t_rev));
    for(int i=0;i<n;i++)
    {
        string l=s.substr(0,i),r=s.substr(i,n);
        reverse(ben(l));
        string a=l+"#"+t;
        string b=r+"#"+t_rev;
        calc(a,p1);
        calc(b,p2);
        for(int j=1;j<=m;j++)
        {
            ll cur1=p1[i+j];
            ll cur2=p2[n+m-j-i];
            if(cur1+cur2>ans[0])
            {
                ans[0]=cur1+cur2;
                ans[1]=i-p1[i+j];
                if(rev)
                {
                    ans[2]=m-j-cur2;
                }
                else ans[2]=j-cur1;
            }
        }
    }
}
int main()
{
    cin>>s>>t;
    n=s.length(),m=t.length();
    solve(s,t,0);
    reverse(ben(t));
    solve(s,t,1);
    cout<<ans[0]<<'\n'<<ans[1]<<" "<<ans[2];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2496 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2496 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 2 ms 2488 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 3 ms 2560 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 3 ms 2532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2496 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 3 ms 2396 KB Output is correct
7 Correct 2 ms 2488 KB Output is correct
8 Correct 3 ms 2396 KB Output is correct
9 Correct 3 ms 2560 KB Output is correct
10 Correct 3 ms 2396 KB Output is correct
11 Correct 2 ms 2396 KB Output is correct
12 Correct 3 ms 2532 KB Output is correct
13 Correct 123 ms 2652 KB Output is correct
14 Correct 99 ms 2652 KB Output is correct
15 Correct 137 ms 2644 KB Output is correct
16 Correct 105 ms 2652 KB Output is correct
17 Correct 90 ms 2604 KB Output is correct
18 Correct 103 ms 2652 KB Output is correct
19 Correct 99 ms 604 KB Output is correct
20 Correct 114 ms 568 KB Output is correct
21 Correct 112 ms 636 KB Output is correct