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 suiii ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define co cout<<
//#pragma GCC optimize("O3,Ofast,unroll-loops")
//#pragma GCC target("avx2,sse3,sse4,avx")
using namespace std;
//stuff
map<string,bool>mp;
map<string,int>mp1;
void rec(string s,ll idx){
if(mp1[s]!=0){
co s.size()<<'\n'<<idx<<' '<<mp1[s]-1;
exit(0);
}
if(mp[s]!=0) return;
mp[s]=1;
string t=s;
reverse(t.begin(),t.end());
rec(t,idx);
s.push_back(s[0]);
s.erase(s.begin());
rec(s,idx);
}
string s,t;
void solve(){
cin>>s>>t;
if(s.size()>t.size()) swap(s,t);
for(int k=s.size();k>0;k--){
for(int i=0;i<t.size();i++){
if(i+k-1>=t.size()) break;
mp1[t.substr(i,k)]=i+1;
}
for(int i=0;i<s.size();i++){
if(i+k-1>=s.size()) break;
rec(s.substr(i,k),i);
}
mp1.clear();
mp.clear();
}
}
int main()
{
suiii
int tt=1;
// cin>>tt;
while(tt--){
solve();
}
return 0;
}
Compilation message (stderr)
necklace.cpp: In function 'void solve()':
necklace.cpp:31:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
31 | for(int i=0;i<t.size();i++){
| ~^~~~~~~~~
necklace.cpp:32:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | if(i+k-1>=t.size()) break;
| ~~~~~^~~~~~~~~~
necklace.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
necklace.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(i+k-1>=s.size()) break;
| ~~~~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |