이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define all(c) (c).begin(), (c).end()
void solve(){
int n;
cin >> n;
string s;
cin >> s;
vector<int> v[26];
for(int i = 0; i < n; i++){
v[s[i] - 'a'].push_back(i);
}
set<char> st;
for(char c : s){
st.insert(c);
}
for(int i = 0; i < 26; i++){
reverse(v[i].begin(), v[i].end());
}
int l = 0,r = 0,a = 1,b = 1;
for(int i = 0; i < n; i++){
vector<int> pos;
for(int j = 0; j < 26; j++){
if(v[j].size() && v[j].back() <= i){
v[j].pop_back();
continue;
}
if(v[j].size()){
pos.push_back(v[j].back());
}
}
sort(pos.rbegin(), pos.rend());
for(int j = 0; j < pos.size(); j++){
if(a * (pos[j] - i) > b * (pos.size() - j)){
l = i,r = pos[j] - 1;
a = (pos.size() - j),b = pos[j] - i;
}
}
if(a * (n - i) > b * (pos.size() + 1)){
l = i,r = n - 1;
a = pos.size() + 1,b = n - i;
}
}
cout << l + 1 << ' ' << 1 + r << endl;
}
signed main(){
#ifndef ONLINE_JUDGE
// freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
nivelle.cpp: In function 'void solve()':
nivelle.cpp:42:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j = 0; j < pos.size(); j++){
| ~~^~~~~~~~~~~~
nivelle.cpp:43:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
43 | if(a * (pos[j] - i) > b * (pos.size() - j)){
| ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp:48:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
48 | if(a * (n - i) > b * (pos.size() + 1)){
| ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |