제출 #844429

#제출 시각아이디문제언어결과실행 시간메모리
844429vjudge1Nivelle (COCI20_nivelle)C++17
0 / 110
2 ms348 KiB
#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)){
      |      ~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
nivelle.cpp: In function 'int main()':
nivelle.cpp:60:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~
nivelle.cpp:60:39: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
      |                                ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...