답안 #887322

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887322 2023-12-14T09:07:16 Z dubabuba Let's Win the Election (JOI22_ho_t3) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int inf = 1e9 + 10;
const int mxn = 20;
int a[mxn], n;
int b[mxn], k;

vector<int> good;
vector<int> badd;

double ans = 1e9;
void solve2(int map) {
	vector<int> vote = badd;
	vector<int> help;
	double ret = 0.0;

	for(int i = 0; i < good.size(); i++)
	if(map & (1 << i))
		help.push_back(good[i]);
	else
		vote.push_back(good[i]);

	if(help.size() > k) return;

	sort(help.begin(), help.end(), [&](int i, int j) { return b[i] < b[j]; });
	sort(vote.begin(), vote.end(), [&](int i, int j) { return a[i] < a[j]; });

	int helpers = 0;
	for(int i : help) {
		ret += 1.0 * b[i] / (1.0 + helpers);
		helpers++;
	}

	for(int j = 0; j < (k - help.size()); j++) {
		int i = vote[j];
		ret += 1.0 * a[i] / (1.0 + helpers);
	}

	ans = min(ans, ret);
}

void sub2() {
	for(int bit = 0; bit < (1 << good.size()); bit++)
		solve2(bit);
	cout << setprecision(5) << fixed << ans << '\n';
	exit(0);
}

void solve1(int t) {
	if(k - t >= badd.size()) return;
	double ret = 0.0;

	int helpers = 0;
	for(int j = 0; j < t; j++) {
		int i = good[j];
		ret += 1.0 * a[i] / (1.0 + helpers);
		helpers++;
	}

	assert(helpers == t);
	for(int j = 0; j < (k - t); j++) {
		if(j >= badd.size())
			for(;;)
		int i = badd[j];
		ret += 1.0 * a[i] / (1.0 + t);
	}

	ans = min(ans, ret);
}

void sub1() {
	sort(good.begin(), good.end(), [&](int i, int j) { return a[i] < a[j]; });
	sort(badd.begin(), badd.end(), [&](int i, int j) { return a[i] < a[j]; });

	for(int i = 0; i <= good.size() && i < k; i++)
		solve1(i);
	cout << setprecision(5) << fixed << ans << '\n';
	exit(0);
}

int main() {
	bool gay = 0;
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> a[i] >> b[i];
		if(b[i] == -1) {
			b[i] = inf;
			badd.push_back(i);
		}
		else {
			if(a[i] != b[i])
				gay = 1;
			good.push_back(i);
		}
	}

	if(n <= 20 && gay) sub2();
	if(!gay) sub1();
	return 0;
}

Compilation message

Main.cpp: In function 'void solve2(int)':
Main.cpp:18:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i = 0; i < good.size(); i++)
      |                 ~~^~~~~~~~~~~~~
Main.cpp:24:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   24 |  if(help.size() > k) return;
      |     ~~~~~~~~~~~~^~~
Main.cpp:35:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int j = 0; j < (k - help.size()); j++) {
      |                 ~~^~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void solve1(int)':
Main.cpp:51:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  if(k - t >= badd.size()) return;
      |     ~~~~~~^~~~~~~~~~~~~~
Main.cpp:63:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   if(j >= badd.size())
      |      ~~^~~~~~~~~~~~~~
Main.cpp:65:7: warning: unused variable 'i' [-Wunused-variable]
   65 |   int i = badd[j];
      |       ^
Main.cpp:66:18: error: 'i' was not declared in this scope
   66 |   ret += 1.0 * a[i] / (1.0 + t);
      |                  ^
Main.cpp: In function 'void sub1()':
Main.cpp:76:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   76 |  for(int i = 0; i <= good.size() && i < k; i++)
      |                 ~~^~~~~~~~~~~~~~