이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
vector<int> prefix_function(string &s) {
int n = (int)s.length();
vector<int> pi(n);
for (int i = 1; i < n; i++) {
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
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]);
auto vc=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]);
vc=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();
}
컴파일 시 표준 에러 (stderr) 메시지
necklace.cpp: In function 'll cal(bool)':
necklace.cpp:41:22: 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 j=0;j<t.size();j++) a.pb(t[j]);
| ~^~~~~~~~~
necklace.cpp:43:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int j=0;j<=t.size();j++)
| ~^~~~~~~~~~
necklace.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for(int j=0;j<=t.size();j++)
| ~^~~~~~~~~~
necklace.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int j=0;j<t.size();j++) a.pb(t[j]);
| ~^~~~~~~~~
necklace.cpp:60:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for(int j=0;j<=t.size();j++)
| ~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |