# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1260404 | tminh | Nivelle (COCI20_nivelle) | C++20 | 23 ms | 328 KiB |
#include "bits/stdc++.h"
using namespace std;
#define task ""
#define ll long long
#define endl '\n'
#define fi first
#define se second
#define vall(a) (a).begin(), (a).end()
#define sze(a) (int)a.size()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ep emplace_back
#define pb push_back
#define pf push_front
const ll mod = 1e9 + 7;
const int N = 1e6 + 5;
const ll oo = 1e18;
bool START;
char a[N];
int n, cnt[26];
inline void solve() {
int tu = n + 1, mau = 1, l = 0, r = 0;
for (int x = 1; x <= 26; ++x) {
for (int i = 0; i < 26; ++i) cnt[i] = 0;
int j = 1, cur = 0;
for (int i = 1; i <= n; ++i) {
// cout << i << " " << j - 1 << " " << cur << endl;
while(j <= n && cur + !cnt[a[j] - 'a'] <= x) {
cur += !cnt[a[j] - 'a'];
++cnt[a[j] - 'a'];
++j;
}
if (cur == x) {
if (mau * x <= tu * (j - i)) {
mau = j - i;
tu = x;
l = i;
r = j - 1;
}
}
--cnt[a[i] - 'a'];
cur -= !cnt[a[i] - 'a'];
}
}
cout << l << " " << r;
}
inline void input() {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
return solve();
}
bool END;
int main() {
if(fopen(task ".inp", "r")) {
freopen(task ".inp", "r", stdin);
freopen(task ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
input();
cerr << endl << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << 's' << endl;
cerr << "Memory: " << fabs ((&END - &START)) / 1048576.0 << "MB\n";
return 0;
}
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... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |