답안 #746296

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746296 2023-05-22T08:26:09 Z bgnbvnbv Necklace (Subtask 4) (BOI19_necklace4) C++14
15 / 15
654 ms 420 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e4;
const ll inf=1e18;
const ll mod=1e9+7;
ll vc[maxN];
void prefix_function(string &s) {
    int n = (int)s.length();
    for (int i = 1; i < n; i++) {
        int j = vc[i-1];
        while (j > 0 && s[i] != s[j])
            j = vc[j-1];
        if (s[i] == s[j])
            j++;
        vc[i] = j;
    }
}
ll n;
string s,t;
ll cnt[maxN];
ll ans=0,id1=0,id2=0;
ll cal(bool tt)
{
    string a;
    for(int i=0;i<=n;i++)
    {
        a.clear();
        for(int j=i;j<n;j++)
        {
            a.pb(s[j]);
        }
        a.pb('#');
        for(int j=0;j<t.size();j++) a.pb(t[j]);
        prefix_function(a);
        for(int j=0;j<=t.size();j++)
        {
            cnt[j]=0;
        }
        for(int j=0;j<=t.size();j++)
        {
            cnt[j]+=vc[j+n-i];
        }
        a.clear();
        for(int j=i-1;j>=0;j--)
        {
            a.pb(s[j]);
        }
        reverse(t.begin(),t.end());
        a.pb('#');
        for(int j=0;j<t.size();j++) a.pb(t[j]);
        prefix_function(a);
        for(int j=0;j<=t.size();j++)
        {
            ll x=cnt[j]+vc[t.size()-j+i];
            if(ans<x)
            {
                ans=x;
                id1=i-vc[t.size()-j+i];
                if(tt)
                {
                    id1=id1+x-1;
                    id1=s.size()-id1-1;
                }
                id2=j-cnt[j];
            }
        }
        reverse(t.begin(),t.end());
    }
    return ans;
}
ll m;
void solve()
{
    cin >> s >> t;
    n=s.size();
    m=t.size();
    cal(0);
    reverse(s.begin(),s.end());
    cal(1);
    cout << ans<<'\n';
    cout << id1<<' '<<id2;
}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

necklace.cpp: In function 'll cal(bool)':
necklace.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int j=0;j<t.size();j++) a.pb(t[j]);
      |                     ~^~~~~~~~~
necklace.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int j=0;j<=t.size();j++)
      |                     ~^~~~~~~~~~
necklace.cpp:46:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(int j=0;j<=t.size();j++)
      |                     ~^~~~~~~~~~
necklace.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         for(int j=0;j<t.size();j++) a.pb(t[j]);
      |                     ~^~~~~~~~~
necklace.cpp:59:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |         for(int j=0;j<=t.size();j++)
      |                     ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 613 ms 404 KB Output is correct
2 Correct 581 ms 408 KB Output is correct
3 Correct 654 ms 408 KB Output is correct
4 Correct 511 ms 420 KB Output is correct
5 Correct 499 ms 412 KB Output is correct
6 Correct 509 ms 412 KB Output is correct
7 Correct 543 ms 416 KB Output is correct
8 Correct 581 ms 340 KB Output is correct
9 Correct 586 ms 420 KB Output is correct