제출 #1285175

#제출 시각아이디문제언어결과실행 시간메모리
1285175hrantsargsyanNivelle (COCI20_nivelle)C++20
7 / 110
39 ms12780 KiB
#include <iostream> #include <string> #include <algorithm> using namespace std; const int N = 2e5; int a[N], nextLetter[N][30]; long long inf = 1e11; int main() { int n, minl = -1, minr = -1; double ans=inf; cin >> n; string s; cin >> s; for (int i = 0;i < s.size();++i) { a[i] = s[i] - 'a' + 1; } for (int i = 0;i< n;++i) { for (int j = 0;j < 30;++j) { nextLetter[i][j] = n; } } nextLetter[n - 1][a[n - 1]] = n-1; for (int i = n - 2;i >= 0;--i) { for (int j = 1;j <= 26;++j) { if (a[i] == j) { nextLetter[i][j] = i; } else { nextLetter[i][j] = nextLetter[i + 1][j]; } } } for (int i = 0;i < n;++i) { sort(nextLetter[i], nextLetter[i] + 26); } //for (int i = 0;i < n;++i) //{ // for (int j = 1;j<=26;++j) // { // cout << i << " " << j <<" "<<nextLetter[i][j] << endl; // } //} for (int i = 0;i < n;++i) { for (int j = 1;j < 26;++j) { int dist = nextLetter[i][j] - i; double currans = (j+1)*1.0 / dist; if (nextLetter[i][j] == n) { currans = j*1.0 / dist; } if (currans < ans) { ans = currans; minl = i; minr = nextLetter[i][j]-1; } if (nextLetter[i][j] == n) { break; } } } cout << minl+1 << " " << minr+1 << endl; //cout << ans << endl; }
#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...