# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
872683 | vjudge1 | Nivelle (COCI20_nivelle) | C++17 | 0 ms | 0 KiB |
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>
#ifdef LOCAL
#include "Essentials/algo/debug.h"
#else
#define debug(...) 69
#endif
using namespace std;
typedef long long ll;
typedef long double ldb;
typedef pair<int,int> pii;
const int N = 1e5 + 23;
const int LOG = 26;
const ll inf = 1e18;
#define F first
#define S second
#define pb push_back
#define kill(x) cout<<x<<endl, exit(0);
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define lc (v << 1)
#define rc ((v<<1) |1)
int n;
string s;
int a[N];
int b[N];
vector<int> vals;
pair<ldb,pii> ans = {1.0 , {1,1}};
bool is[(1 << 26)+ 23];
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
void check(int x) {
if(is[x]) continue;
is[x] = true;
int l = 1;
int s = __builtin_popcount(x);
for(int i = 1 ; i<=n ; i++) {
b[i] = (x >> a[i]) &1;
//debug(i,b[i]);
if(b[i] == 0) {
if(b[i-1] == 0 || i == 1) {
l = i+1;
continue;
}
int r = i-1;
debug((ldb)s/(r-l+1),s,(r-l+1));
ans = min(ans, {(ldb)s/(r-l+1), {l,r}});
l = i+1;
}
if(i > 1 && b[i] == b[i-1] && b[i] == 1) {
debug(x,i,i-1);
}
}
if(b[n] != 0) {
int r = n;
ans = min(ans, {(ldb)s/(r-l+1), {l,r}});
}
}
bool mark[LOG+23];
int32_t main() {
cin.tie(nullptr)->sync_with_stdio(false);
cin>>n>>s;
vector<int> sex;
for(int i = 1; i<= n ; i++) {
a[i] = s[i-1] -'a';
}
sex.pb(a[n]);
vals.pb(a[n]);
for(int i = 1; i<= n; i++) {
if(!mark[a[i]]) {
sex.pb(a[i]);
int f = 0;
for(int j = sz(sex)-1; j>= 0 ;j--) {
int x = sex[j];
f |= (1 << x);
vals.pb(f);
}
mark[a[i]] = true;
} else {
sex.erase(find(all(sex),a[i]));
sex.pb(a[i]);
int f = 0;
for(int j = sz(sex)-1; j>= 0 ;j--) {
int x = sex[j];
f |= (1 << x);
vals.pb(f);
}
}
}
//sort(all(vals));
//vals.resize(unique(all(vals)) - vals.begin());
for(int x : vals) check(x);
cout<<ans.S.F << ' '<< ans.S.S << '\n';
return 0;
}