Submission #844435

#TimeUsernameProblemLanguageResultExecution timeMemory
844435vjudge1Nivelle (COCI20_nivelle)C++17
110 / 110
884 ms24916 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)); } } pair<int, int> best = {1, 1}; int bl = 1, br = 1; for(int i = 1; i <= 26; i++){ for(int j = 0; j < n; j++){ int lint = 0; int l = j+1, r = n+1; while(l < r){ int m = (l + r)/2; int s = 0; for(int k = 0; k < 26; k++){ s += (pre[m][k] > pre[j][k]); } if(s <= i){ lint = max(lint, m); l = m + 1; } else{ r = m; } } pair<int, int> op = {lint - j, i}; if(best.first * op.second < best.second * op.first){ bl = j+1, br = lint; best = op; } } } cout<<bl<<" "<<br<<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...