이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FORI(i, n) for(ll i = 0; i < n; i++)
#define FOR(i, n) for(ll i = 1; i <= n; i++)
typedef vector<ll> vl;
typedef set<ll> setl;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define pll pair<ll, ll>
#define db double
#define nll cout << "\n"
#define nl "\n"
#define sync ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll INF = 1e9 + 7;
const int MAX = 3e5 + 5;
ll n, m, k;
// ll a, b;
ll a[MAX];
void solve(){
cin >> n;
string s;
cin >> s;
s = " " + s;
ll l = 0, r = 0, best = 0;
for(ll dis = 1; dis <= 26; dis++){
map < char, ll > cnt;
ll sum = 0, lx = 1;
FOR(i, n){
cnt[s[i]]++;
if(cnt[s[i]] == 1)sum++;
while(sum > dis){
cnt[s[lx]]--;
if(cnt[s[lx]] == 0)sum--;
lx++;
}
if(l == 0 || best * (i - lx + 1) > sum * (r - l + 1)){
l = lx, r = i, best = sum;
}
}
}
cout << l << " " << r << nl;
}
signed main(){
sync;
ll t = 1;
// cin >> t;
while(t--) {
solve();
}
}
# | 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... |