# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1244808 | CrabCNH | Nivelle (COCI20_nivelle) | C++20 | 48 ms | 584 KiB |
#include <bits/stdc++.h>
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
using namespace std;
const int N = 1e5 + 5;
const int inf = 1e18 + 7;
int n, a[N];
map <int, int> mp;
int last[27];
string s;
void sub2 () {
int bestL = -1, bestR = -1, bestCnt = 26;
for (int i = 0; i < n; i ++) {
mp.clear ();
int cnt = 0;
for (int j = i; j < n; j ++) {
if (mp.find (s[j] - 'a') == mp.end ()) {
mp[s[j] - 'a'] ++;
cnt ++;
}
if (cnt *(bestR - bestL + 1) < bestCnt * (j - i + 1)) {
bestL = i;
bestR = j;
bestCnt = cnt;
//cout << bestL << " " << bestR << ' ' << bestCnt << '\n';
}
}
}
cout << bestL + 1 << ' ' << bestR + 1;
}
void subfull () {
int bestL = -1, bestR = -1, bestCnt = 26;
vector <int> all (27, -1);
memset (last, -1, sizeof (last));
for (int j = 0; j < n; j ++) {
all.erase (find (all.begin (), all.end (), last[s[j] - 'a']));
last[s[j] - 'a'] = j;
all.insert (all.begin (), j);
for (int cnt = 1; cnt <= 26; cnt ++) {
int i = all[cnt] + 1;
if (cnt *(bestR - bestL + 1) < bestCnt * (j - i + 1)) {
bestL = i;
bestR = j;
bestCnt = cnt;
//cout << bestL << " " << bestR << ' ' << bestCnt << '\n';
}
}
}
cout << bestL + 1 << ' ' << bestR + 1;
}
signed main () {
ios_base :: sync_with_stdio (0);
cin.tie (0);
cout.tie (0);
#define task "crab"
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
cin >> n >> s;
if (n <= 2000) {
sub2 ();
}
else {
subfull ();
}
}
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... |