제출 #844510

#제출 시각아이디문제언어결과실행 시간메모리
844510vjudge1Nivelle (COCI20_nivelle)C++17
110 / 110
167 ms24404 KiB
#include "bits/stdc++.h" using namespace std; #define pb push_back #define endl "\n" #define int long long #define sz(x) ((int)(x).size()) #define all(x) (x).begin(),(x).end() #define rall(x) (x).rbegin(),(x).rend() const int INF = 1e18; void solve() { int n; cin >> n; string s; cin >> s; s=" " + s; int pre[n+1][30]; for(int i=0;i<30;i++) pre[0][i]=0; int pay=1,payda=1; int a=1,b=1; for(int i=1;i<=n;i++) { for(int j=0;j<30;j++) pre[i][j]=pre[i-1][j]; pre[i][s[i]-'a'+1]=i; } for(int i=1;i<=n;i++) { int p=i; int ok=(1LL<<(s[i]-'a'+1)); for(int j=1;j<=30;j++) { int nearest=-1; for(int k=1;k<=26;k++) { if(ok>>k&1) continue; if(pre[p][k]!=0 && pre[p][k] < p) nearest=max(nearest,pre[p][k]); } if(nearest==-1) { int cpay=__builtin_popcountll(ok); int cpayda=i; if(cpay*payda<pay*cpayda) { pay=cpay; payda=cpayda; b=i; a=1; } } else { int cpay=__builtin_popcountll(ok); int cpayda=i-nearest; if(cpay*payda<pay*cpayda) { pay=cpay; payda=cpayda; b=i; a=nearest+1; } } p=nearest; ok|=(1LL<<(s[nearest]-'a'+1)); } } cout << a << " " << b << endl; } int32_t main(){ cin.tie(0); ios::sync_with_stdio(0); int t=1;//cin >> t; while(t--) solve(); 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...