이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define int long long
using namespace std;
const int inf = 2e18 + 5;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
int32_t main(){
//freopen("in.txt","r", stdin);
int n;
cin>>n;
string s;
cin>>s;
int mx = 0;
vector<vector<int> > pre(n+1, vector<int>(26));
for(int i = 0; i < n; i++){
mx = max(mx, (int)(s[i] - 'a'));
for(int j = 0; j < 26; j++){
pre[i+1][j] = pre[i][j] + (s[i] == (char)('a' + j));
}
}
if(mx <= 2){
int mxlen = 1;
int l = 1, r = 1;
int lst = s[0] - 'a', len = 1;
for(int i = 1; i < n; i++){
if(s[i] - 'a' != lst){
if(len > mxlen){
r = i;
l = i - len + 1;
mxlen = len;
}
if(s[i] == 'b') lst = 1;
else lst = 0;
len = 1;
}
else{
len++;
}
}
if(len > mxlen){
r = n;
l = n - len + 1;
mxlen = len;
}
cout<<l<<" "<<r<<endl;
return 0;
}
pair<int, int> best = {1, 1};
int l = 1, r = 1;
for(int i = 0; i < n; i++){
for(int j = i+1; j <= n; j++){
int df = 0, len = j - i;
for(int k = 0; k < 26; k++){
if(pre[j][k] - pre[i][k] > 0) df++;
}
pair<int, int> option = {len, df};
if(best.first * option.second < option.first * best.second){
best = {len, df};
r = j, l = i+1;
}
}
}
cout<<l<<" "<<r<<endl;
return 0;
}
# | 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... |