#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+1,d);
reverse(t.begin(),t.end());
t=a[l]+t;
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
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;
| ~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
363 ms |
7916 KB |
Output is correct |
2 |
Correct |
427 ms |
6668 KB |
Output is correct |
3 |
Correct |
307 ms |
1996 KB |
Output is correct |
4 |
Correct |
343 ms |
1104 KB |
Output is correct |
5 |
Correct |
452 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
363 ms |
7916 KB |
Output is correct |
2 |
Correct |
427 ms |
6668 KB |
Output is correct |
3 |
Correct |
307 ms |
1996 KB |
Output is correct |
4 |
Correct |
343 ms |
1104 KB |
Output is correct |
5 |
Correct |
452 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
1583 ms |
344 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
363 ms |
7916 KB |
Output is correct |
2 |
Correct |
427 ms |
6668 KB |
Output is correct |
3 |
Correct |
307 ms |
1996 KB |
Output is correct |
4 |
Correct |
343 ms |
1104 KB |
Output is correct |
5 |
Correct |
452 ms |
344 KB |
Output is correct |
6 |
Execution timed out |
1583 ms |
344 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |