#include "bits/stdc++.h"
using namespace std;
#define ll long long int
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
return a.second - a.first > b.second - b.first;
}
int main(int argc, char const *argv[]) {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
string s;
cin >> n;
cin >> s;
if (count(s.begin(), s.end(), 'a') + count(s.begin(), s.end(), 'b') == n) {
ll a = 0, b = 0;
for (auto i : s) a |= (i == 'a'), b |= (i == 'b');
ll hor = 0;
ll cnt = 0;
ll l = 0, r = 0;
vector<pair<ll, ll>> v;
char pre = '$';
for (ll i = 0; i < n; i++) {
if (pre == '$') cnt = 1, pre = s[i], l = 0;
else if (s[i] != pre) {
r = i - 1;
v.push_back({l, r});
l = i;
pre = s[i];
}
}
v.push_back({l, n - 1});
sort(v.begin(), v.end(), cmp);
if (a && b) {
ll d1 = v[0].second - v[0].first + 1;
ll d2 = n;
ll l1 = 1;
ll l2 = 2;
if (l1 * d2 > l2 * d1) {
cout << 1 << " " << n << endl;
} else {
cout << v[0].first + 1 << " " << v[0].second + 1;
}
} else {
cout << v[0].first + 1 << " " << v[0].second + 1;
}
return 0;
}
set<char> st;
vector<pair<pair<ll, ll>, pair<ll, ll>>> v;
//ll l2 = 10000, d2 = 10000;
for (ll i = 0; i < n; i++) {
map<char, ll> mp;
ll l1 = 0, l2 = 0;
st.insert(s[i]);
for (ll j = i; j < n; j++) {
if (!mp[s[j]]) {
l1++;
mp[s[j]]++;
}
l2++;
v.push_back({{i, j}, {l1, l2}});
}
}
ll l, r;
ll c1 = 10000, c2 = 10000;
for (auto i : v) {
ll h1 = i.second.first;
ll h2 = i.first.second - i.first.first + 1;
if (c1 * h2 > h1 * c2) {
l = i.first.first + 1;
r = i.first.second + 1;
c1 = h1;
c2 = h2;
}
}
if (st.size() == n) cout << "1 1" << endl;
else cout << l << " " << r << endl;
return 0;
}
Compilation message
klasika.cpp: In function 'int main(int, const char**)':
klasika.cpp:17:6: warning: unused variable 'hor' [-Wunused-variable]
17 | ll hor = 0;
| ^~~
klasika.cpp:18:6: warning: variable 'cnt' set but not used [-Wunused-but-set-variable]
18 | ll cnt = 0;
| ^~~
klasika.cpp:76:17: warning: comparison of integer expressions of different signedness: 'std::set<char>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
76 | if (st.size() == n) cout << "1 1" << endl;
| ~~~~~~~~~~^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
972 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1480 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |