Submission #844606

#TimeUsernameProblemLanguageResultExecution timeMemory
844606vjudge1Nivelle (COCI20_nivelle)C++17
0 / 110
1055 ms648 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #include "/Users/kutay/CP/templates/debug.h" #else #define debug(...) void(38) #endif #define int long long int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; string s; cin >> s; double d = 1e9; pair<int, int> ans; for (int a = 1; a <= 26; a++) { vector<int> m(26); int l = 0, r = 0; int cnt = 0; while (r < n && cnt <= a) { m[s[r++] - 'a']++; int c = 0; for (int x : m) c += (bool) x; cnt = c; if (c > a) { r--; break; } } r--; if ((double) a / (r - l + 1) - d < -1e-7) { d = (double) a / (r - l + 1); ans = make_pair(l, r); } debug(a, l, r, d); while (r < n - 1) { r++; cnt = a; while (r < n && cnt <= a + 1) { m[s[r++] - 'a']++; int c = 0; for (int x : m) c += (bool) x; cnt = c; if (c > a + 1) { r--; break; } } r--; debug(l, r); while (l < n && cnt > a) { m[s[l++] - 'a']--; int c = 0; for (int x : m) c += (bool) x; cnt = c; } l--; debug(l, r); if ((double) a / (r - l + 1) < d) { d = (double) a / (r - l + 1); ans = make_pair(l, r); } } } cout << ans.first + 1 << " " << ans.second + 1 << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...