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;
typedef int ll;
//#define int long long
#define F first
#define S second
#define endl '\n'
#define INT INT_MAX
int const M = 301 , Mx = 1e5 , N = 4e6 + 2 , lg = 30 , mod = 1e9 + 7;
int dx[] = {0 , 0 , -1 , 1 , 1 , 1 , -1 , -1};
int dy[] = {1 , -1 , 0 , 0 , 1 , -1 , 1 , -1};
int T , n , m , ans , A , B , sz1 , sz2;
string a , b;
map<string , ll>mp;
main() {
ios_base::sync_with_stdio(false);cout.tie(nullptr);cin.tie(nullptr);
cin >> a >> b;
sz1 = a.size();
sz2 = b.size();
for(int i = 0 ; i < sz1 ; ++i) {
for(int j = i ; j < sz1 ; ++j) {
for(int I = i ; I <= j ; ++I) {
string res1 = "" , res2 = "";
for(int J = I ; J <= j ; ++J) res1 += a[J];
for(int J = i ; J < I ; ++J) res1 += a[J];
for(int J = I ; J >= i ; --J) res2 += a[J];
for(int J = j ; J > I ; --J) res2 += a[J];
mp[res1] = I + 1;
mp[res2] = I + 1;
}
}
}
for(int i = 0 ; i < sz2 ; ++i) {
for(int j = i ; j < sz2 ; ++j) {
for(int I = i ; I <= j ; ++I) {
string res1 = "" , res2 = "";
for(int J = I ; J <= j ; ++J) res1 += b[J];
for(int J = i ; J < I ; ++J) res1 += b[J];
for(int J = I ; J >= i ; --J) res2 += b[J];
for(int J = j ; J > I ; --J) res2 += b[J];
if(mp[res1] && res1.size() > ans) {
ans = res1.size();
A = mp[res1] - 1;
B = I;
}
if(mp[res2] && res2.size() > ans) {
ans = res2.size();
A = mp[res2] - 1;
B = I;
}
}
}
}
cout << ans << endl;
cout << A << " " << B << endl;
return 0;
}
Compilation message (stderr)
necklace.cpp:16:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
16 | main() {
| ^~~~
necklace.cpp: In function 'int main()':
necklace.cpp:53:44: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
53 | if(mp[res1] && res1.size() > ans) {
| ~~~~~~~~~~~~^~~~~
necklace.cpp:59:44: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
59 | if(mp[res2] && res2.size() > ans) {
| ~~~~~~~~~~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |