Submission #530141

# Submission time Handle Problem Language Result Execution time Memory
530141 2022-02-24T17:10:32 Z LucaDantas CONSUL (info1cup19_consul) C++17
19 / 100
119 ms 312 KB
#include "grader.h"
#include <bits/stdc++.h>
using namespace std;

constexpr int maxn = 1e5+10, SZ = 100, tot = 110;

mt19937 rng(random_device{}());

int rnd(int x) { return (rng() % x + x) % x; }

int a[maxn], mark[maxn];

void solve(int n)
{
	vector<int> usar;
	map<int,int> freq;
	while(usar.size() < min(n, SZ)) {
		int rd = rnd(n)+1;
		if(!mark[rd])
			usar.push_back(rd), a[rd] = kth(rd), freq[a[rd]]++;
		mark[rd] = 1;
	}
	for(int x : usar)
		mark[x] = 0;

	vector<pair<int,int>> maiores;
	for(auto it : freq)
		maiores.push_back({it.second, it.first});
	sort(maiores.begin(), maiores.end(), greater<pair<int,int>>());

	while(maiores.size() > tot - SZ)
		maiores.pop_back();

	if(n <= 100) {
		if(maiores[0].first > n/3) say_answer(maiores[0].second);
		else say_answer(-1);
		return;
	}

	for(int i = 0; i < maiores.size(); i++)
		if(cnt(maiores[i].second) > n/3) return (void)(say_answer(maiores[i].first));

	say_answer(-1);
}

Compilation message

consul.cpp: In function 'void solve(int)':
consul.cpp:17:20: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'const int' [-Wsign-compare]
   17 |  while(usar.size() < min(n, SZ)) {
      |        ~~~~~~~~~~~~^~~~~~~~~~~~
consul.cpp:40:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |  for(int i = 0; i < maiores.size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Partially correct 119 ms 200 KB Output is partially correct
2 Partially correct 95 ms 300 KB Output is partially correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 312 KB Wrong answer
2 Halted 0 ms 0 KB -