This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
bool check(string s, string t){
if(s==t)return 1;
string h;
int n=s.size();
for(int i=1;i<s.size();i++){
int r=n-i;
if(s.substr(0,i)==t.substr(n-i,i) and s.substr(n-r,r)==t.substr(0,r) )return 1;
}
return 0;
}
signed main(){
string a,b;
cin>>a>>b;
vector<pair<int,pair<int,int>>>v;
for(int l=0;l<a.size();l++){
for(int r=l;r<a.size();r++){
for(int x=0;x<b.size();x++){
int d=r-l;
int y=x+d;
if(y>=b.size())continue;
string s=a.substr(l,d+1);
string t=a.substr(l,d+1);
reverse(t.begin(),t.end());
if(check(s,b.substr(x,d+1)) or check(t,b.substr(x,d+1))){
v.pb({-d-1,{l,x}});
}
}
}
}
sort(v.begin(),v.end());
cout<<-v[0].ff<<endl;
cout<<v[0].ss.ff<<" "<<v[0].ss.ss;
}
Compilation message (stderr)
necklace.cpp: In function 'bool check(std::string, std::string)':
necklace.cpp:11:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
necklace.cpp: In function 'int main()':
necklace.cpp:21:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | for(int l=0;l<a.size();l++){
| ~^~~~~~~~~
necklace.cpp:22:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int r=l;r<a.size();r++){
| ~^~~~~~~~~
necklace.cpp:23:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int x=0;x<b.size();x++){
| ~^~~~~~~~~
necklace.cpp:26:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if(y>=b.size())continue;
| ~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |