Submission #746296

#TimeUsernameProblemLanguageResultExecution timeMemory
746296bgnbvnbvNecklace (Subtask 4) (BOI19_necklace4)C++14
15 / 15
654 ms420 KiB
#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 (stderr)

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++)
      |                     ~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...