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>
//#pragma GCC optimize("O2")
//#pragma GCC target("avx,avx2,fma")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define PB push_back
#define ALL(i_) i_.begin(), i_.end()
#define LOG2(x) (31 - __builtin_clz(x))
#define getBit(x, i) ((x >> i) & 1)
#define rd(l, r) (l + rng() % (r - l + 1))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
template<class X, class Y> bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {
x = y;
return 1;
}
return 0;
}
template<class X, class Y> bool maximize(X &x, const Y &y) {
X eps = 1e-9;
if (x + eps < y) {
x = y;
return 1;
}
return 0;
}
template<class T> T Abs(const T &x) { return (x < 0 ? -x : x); }
const int mod = (int) 1e9 + 7;
const int oo = (int) 1e9 + 99;
const int maxn = (int) 1e5 + 11;
const int LOG = (int) 17;
const ii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
int n;
int cnt[26];
string s;
ld res = 1e18;
ii ans;
void Add(int i, int &val){
++cnt[s[i] - 'a'];
if(cnt[s[i] - 'a'] == 1) ++val;
}
void Sub(int i, int &val){
--cnt[s[i] - 'a'];
if(cnt[s[i] - 'a'] == 0) --val;
}
void Update(int k, int l, int r){
ld val = (1.0 * k) / (1.0 * r - 1.0 * l + 1.0);
if(res > val){
res = val;
ans = {l, r};
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define TASK "NIVELLE"
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >> n >> s;
s = " " + s;
for(int num = 1; num <= 26; num++){
memset(cnt, 0, sizeof cnt);
int cur = 0;
for(int l = 1, r = 1; r <= n; r++){
Add(r, cur);
while(cur > num) Sub(l++, cur);
Update(num, l, r);
}
}
cout << ans.first << " " << ans.second << "\n";
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:71:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:72:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |