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>
#define int long long
using namespace std;
struct answer{
int a, x, y;
};
bool are_equal(const string& s, const string& t){
if(s.length() != t.length()) return false;
for(int i = 0; i < s.length(); i++){
bool eq = true;
for(int j = 0; j < s.length(); j++){
eq &= s[j] == t[(i + j) % s.length()];
}
if(eq) return true;
}
return false;
}
answer query(const string& s, const string& t){
int n = s.size(), m = t.size();
answer ans {-1, 0, 0};
for(int l = 1; l <= min(n, m); l++){
for(int i = 0; i <= n - l; i++){
for(int j = 0; j <= m - l; j++){
bool ok = are_equal(s.substr(i, l), t.substr(j, l));
if(ok){
ans = answer {l, i, j};
}
}
}
}
return ans;
}
int32_t main(){
string s, t; cin >> s >> t;
answer a1 = query(s, t);
reverse(t.begin(), t.end());
answer a2 = query(s, t); a2.y = t.size() - (a2.y + a2.a);
answer ans; ans.a = -1;
if(a1.a > ans.a) ans = a1;
if(a2.a > ans.a) ans = a2;
cout << ans.a << endl;
cout << ans.x << ' ' << ans.y << endl;
}
Compilation message (stderr)
necklace.cpp: In function 'bool are_equal(const string&, const string&)':
necklace.cpp:11:19: 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 = 0; i < s.length(); i++){
| ~~^~~~~~~~~~~~
necklace.cpp:13:20: 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]
13 | for(int j = 0; j < s.length(); 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... |