Submission #315042

# Submission time Handle Problem Language Result Execution time Memory
315042 2020-10-22T01:13:08 Z thtsshz_bgwrswh CONSUL (info1cup19_consul) C++17
100 / 100
45 ms 384 KB
#pragma GCC optimize("Ofast")
#include "grader.h"
#include<algorithm>
#include<random>
#include<vector>
#include<utility>
#include<map>
using namespace std;
int order[1005];
map<int,int> m;
vector<pair<int,int>> q;
void solve(int n){
	int i;
	for(i=1;i<=n;i++)
		order[i]=i;
	random_shuffle(order+1,order+n+1);
	m.clear();
	for(i=1;i<=25;i++)
		m[kth(order[i])]++;	
	q.clear();
	for(auto x:m)
		q.emplace_back(x.second,x.first);
	sort(q.begin(),q.end());
	reverse(q.begin(),q.end());
	if(n<=50){
		int ans=0,v;
		for(i=0;i<25&&i<(int)q.size();i++){
			int temp=cnt(q[i].second);
			if(temp>ans){
				ans=temp;
				v=q[i].second;
			}
		}
		if(ans>n/3)
			say_answer(v);
		else
			say_answer(-1);
	}
	else{
		int ans=0,v;
		for(i=0;i<35&&i<(int)q.size();i++){
			int temp=cnt(q[i].second);
			if(temp>ans){
				ans=temp;
				v=q[i].second;
			}
		}
		if(ans>n/3)
			say_answer(v);
		else
			say_answer(-1);
	}
}

Compilation message

consul.cpp: In function 'void solve(int)':
consul.cpp:49:14: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   49 |    say_answer(v);
      |    ~~~~~~~~~~^~~
consul.cpp:35:14: warning: 'v' may be used uninitialized in this function [-Wmaybe-uninitialized]
   35 |    say_answer(v);
      |    ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 24 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 256 KB Output is correct
2 Correct 29 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 256 KB Output is correct
2 Correct 38 ms 256 KB Output is correct
3 Correct 30 ms 384 KB Output is correct
4 Correct 25 ms 256 KB Output is correct
5 Correct 35 ms 256 KB Output is correct
6 Correct 38 ms 256 KB Output is correct
7 Correct 34 ms 256 KB Output is correct
8 Correct 42 ms 256 KB Output is correct
9 Correct 45 ms 384 KB Output is correct
10 Correct 43 ms 256 KB Output is correct
11 Correct 44 ms 256 KB Output is correct
12 Correct 38 ms 256 KB Output is correct
13 Correct 34 ms 256 KB Output is correct
14 Correct 45 ms 256 KB Output is correct