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>
#define ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 2e3+5;
const int M = 1e5+5;
const int mod = 1e9+7;
const ll base = 327;
const ll inf = 1e15+7;
int c[N], d[N], ans, tong, dp[N], h[N];
int n, m, k;
int a[52], b[N];
vector<int> adj[N], vi, gr[N];
void add(int& x, int y)
{
x += y;
if(x >= mod)x -= mod;
}
struct BIT
{
int n;
vector<ll> fe;
BIT(){}
void init(int _n)
{
n = _n;
fe.assign(n+1, 0);
}
void add(int id, ll x)
{
for(; id <= n; id += id & -id)fe[id] += x;
}
void add(int l, int r, ll x)
{
add(l, x);
add(r+1, -x);
}
ll get(int id)
{
ll res = 0;
for(; id; id -= id & -id)res += fe[id];
return res;
}
}L, R;
void sol()
{
string s;
srand((int)(time(0)));
cin >> n >> s;
ld res = inf;
int l = 1, r = 1;
for(int len = 1; len <= 26; len ++)
{
m = 0;
fill_n(a, 26, 0);
for(int i = 1, j = 1; i <= n; i ++)
{
k = s[i-1]-'a';
++a[k];
if(a[k] == 1)++m;
while(m > len)
{
k = s[j-1]-'a';
--a[k];
if(a[k] == 0)--m;
++j;
}
if(res > m*1.0/(i-j+1))
{
res = m*1.0/(i-j+1);
l = j;
r = i;
}
}
}
cout << l <<" "<<r;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
Compilation message (stderr)
nivelle.cpp: In function 'int main()':
nivelle.cpp:94:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:95:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
95 | 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... |