| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 524494 | Jarif_Rahman | Necklace (Subtask 1-3) (BOI19_necklace1) | C++17 | 1584 ms | 108884 KiB |
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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
vector<str> lex(str s){
int n = s.size();
char a = *min_element(s.begin(), s.end());
vector<int> c;
for(int i = 0; i < n; i++) if(s[i] == a) c.pb(i);
vector<str> rt;
auto startswith = [&s, &n](int k){
str rt = "";
for(int i = k; i < n; i++) rt+=s[i];
for(int i = 0; i < k; i++) rt+=s[i];
return rt;
};
if(c.size() == 1) return {startswith(c[0])};
int mn = 1e9, k = -1;
for(int i = 0; i < c.size(); i++){
int ii = (i+1)%c.size();
int cur = c[i]+1;
cur+=n-c[ii];
if(cur < mn) mn = cur, k = ii;
}
if(s.size()%2 == 0 && s.size()/2 == mn-1){
return {startswith(c[k]), startswith(c[(k-1+c.size())%c.size()])};
}
else return {startswith(c[k])};
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
str s1, s2; cin >> s1 >> s2;
int n = s1.size(), m = s2.size();
unordered_map<str, pair<int, int>> mp;
for(int i = 0; i < n; i++) for(int j = i; j < n; j++){
str ss = "";
for(int k = i; k <= j; k++) ss+=s1[k];
for(str h: lex(ss)){
if(mp.find(h) == mp.end() || mp[h].f < j-i+1) mp[h] = {j-i+1, i};
}
reverse(ss.begin(), ss.end());
for(str h: lex(ss)){
if(mp.find(h) == mp.end() || mp[h].f < j-i+1) mp[h] = {j-i+1, i};
}
}
int ans = 0, a = 0, b = 0;
for(int i = 0; i < m; i++) for(int j = i; j < m; j++){
str ss = "";
for(int k = i; k <= j; k++) ss+=s2[k];
for(auto h: lex(ss)){
if(mp[h].f > ans) ans = mp[h].f, a = mp[h].sc, b = i;
}
reverse(ss.begin(), ss.end());
for(auto h: lex(ss)){
if(mp[h].f > ans) ans = mp[h].f, a = mp[h].sc, b = i;
}
}
cout << ans << "\n";
cout << a << " " << b << "\n";
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
