Submission #844562

# Submission time Handle Problem Language Result Execution time Memory
844562 2023-09-05T14:09:25 Z vjudge1 Nivelle (COCI20_nivelle) C++17
0 / 110
178 ms 756 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
	int n;cin>>n;
	string str;cin>>str;
	vector<int> ilk(26,-1);
	vector<int> son(26,-1);
	for (int i = 0; i < n; i++){
		if (ilk[str[i]-'a']==-1) ilk[str[i]-'a']=i;
		son[str[i]-'a']=i;
	}
	vector<int> ls;
	vector<int> rs;
	for (int i = 0; i < 26; i++){
		if (son[i]==-1) continue;
		ls.push_back(son[i]+1);
		ls.push_back(ilk[i]);
		rs.push_back(ilk[i]-1);
		rs.push_back(son[i]);
	}
	vector<bool> vis(26,true);
	double hueh = n;
	int ansl, ansr;
	for (int ll = 0; ll < ls.size(); ll++){
		for (int rr = 0; rr < rs.size(); rr++){
			int l = ls[ll];
			int r = rs[rr];
			if (l>r) continue;
			fill(vis.begin(), vis.end(), 0);
			int crr = 0;
			for (int i = l; i <= r; i++){
				if (!vis[str[i]-'a']) crr++;
				vis[str[i]-'a']=true;
			}
			if ((double)crr/(r-l+1)<hueh){
				hueh=(double)crr/(r-l+1);
				ansl = l;
				ansr = r;
			}
		}
	}
	cout<<ansl+1<<" "<<ansr+1<<endl;
}

Compilation message

nivelle.cpp: In function 'int32_t main()':
nivelle.cpp:25:22: 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]
   25 |  for (int ll = 0; ll < ls.size(); ll++){
      |                   ~~~^~~~~~~~~~~
nivelle.cpp:26:23: 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]
   26 |   for (int rr = 0; rr < rs.size(); rr++){
      |                    ~~~^~~~~~~~~~~
nivelle.cpp:43:26: warning: 'ansr' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |  cout<<ansl+1<<" "<<ansr+1<<endl;
      |                          ^
nivelle.cpp:43:13: warning: 'ansl' may be used uninitialized in this function [-Wmaybe-uninitialized]
   43 |  cout<<ansl+1<<" "<<ansr+1<<endl;
      |             ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 1 ms 348 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 178 ms 756 KB Output isn't correct
2 Halted 0 ms 0 KB -