제출 #844403

#제출 시각아이디문제언어결과실행 시간메모리
844403vjudge1Nivelle (COCI20_nivelle)C++17
24 / 110
1053 ms24664 KiB
#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 <= 1){ 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...