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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int int64_t
#define ordered_set \
tree<int, null_type, less<int>, rb_tree_tag, \
tree_order_statistics_node_update>
#define F first
#define S second
#define I insert
#define PB push_back
#define POB pop_back
#define sqr(a) ((a) * (a))
#define P pop
#define max3(a, b, c) (max(a, max(b, c)))
#define max4(a, b, c, d) (max(max(a, b), max(c, d)))
#define min3(a, b, c) (min(a, min(b, c)))
#define min4(a, b, c, d) (min(min(a, b), min(c, d)))
#define MOD 1000000007
#define mod 998244353
int binpow(int a, int p, int m = MOD) {
int ans = 1;
while (p) {
if (p & 1) ans = ((ans % m) * (a % m)) % m;
a = sqr(a) % m;
p >>= 1;
}
return ans;
}
void solve() {
int n;
string s;
cin >> n >> s;
set<char> sc;
for (int i = 0; i < n; i++) sc.I(s[i]);
double mini = 1;
pair<int, int> posi = {0, 0};
for (int i = 1; i <= sc.size(); i++) {
int r = 0, l = 0;
map<char, int> m;
m[s[r]]++;
while (true) {
if (l == n - 1) break;
l++;
m[s[l]]++;
while (m.size() > i) {
m[s[r]]--;
if (m[s[r]] == 0) m.erase(s[r]);
r++;
}
double curr = double(m.size()) / (l - r + 1);
if (mini > curr) {
mini = curr;
posi.F = r;
posi.S = l;
}
}
}
cout << posi.F + 1 << ' ' << posi.S + 1;
}
int32_t main() {
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
Compilation message (stderr)
nivelle.cpp: In function 'void solve()':
nivelle.cpp:41:23: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::set<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for (int i = 1; i <= sc.size(); i++) {
| ~~^~~~~~~~~~~~
nivelle.cpp:49:29: warning: comparison of integer expressions of different signedness: 'std::map<char, long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
49 | while (m.size() > i) {
| ~~~~~~~~~^~~
# | 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... |