이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
template<class ISqr, class T>
ISqr& operator>>(ISqr& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
#define SPEED \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL);
template <typename T>
void show(vector<T> &v) {
for (T i : v) {
cout << i << ' ';
}
cout << endl;
}
#define pb push_back
#define ins insert
#define fi first
#define se second
#define endl "\n"
#define ALL(x) x.begin(), x.end()
#define sz(x) x.size()
#define int long long
#define _ << " " <<
#define no cout << "No" << endl;
#define yes cout << "Yes" << endl;
#define impos cout << -1 << endl;
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
const int inf = 2e18;
const int sze = 5005;
void solve() {
int n; string s;
cin >> n >> s;
s = '$' + s;
int l = 0, r = 0, ans = 0;
for(int sze = 1; sze <= 26; sze++) {
map<int,int>cnt;
int cur = 0, curl = 1 ;
for(int i = 1; i <= n; i++) {
cnt[s[i]]++;
if(cnt[s[i]] == 1) cur++;
while(cur > sze) {
cnt[s[curl]]--;
if(cnt[s[curl]] == 0) cur--;
curl++;
}
if(ans * (i - curl + 1) > cur * (r - l + 1) || l == 0) {
l = curl; r = i; ans = cur;
}
}
}
cout << l << " " << r << endl;
}
signed main(){
SPEED;
int t = 1;
// cin >> t;
for(int cs = 1; cs <= t; cs++) {
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... |