답안 #598888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
598888 2022-07-19T07:12:11 Z denniskim Let's Win the Election (JOI22_ho_t3) C++17
21 / 100
1651 ms 448 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second

ll n;
ll k;
pair< pair<ll, ll>, ll> a[510];
pair<ll, ll> won[510];
ld ans = INF;
ll chk[510];

ld calc(void)
{
	vector<ll> aa, bb;
	ld ret = 0;
	ll ppl = 1;
	
	for(ll i = 1 ; i <= n ; i++)
	{
		if(chk[i] == 1)
			aa.push_back({won[i].se});
		else if(chk[i] == 2)
			bb.push_back({won[i].fi});
	}
	
	sort(bb.begin(), bb.end());
	
	for(auto &i : bb)
	{
		ret += (ld)i / (ld)ppl;
		ppl++;
	}
	
	for(auto &i : aa)
		ret += (ld)i / (ld)ppl;
	
	return ret;
}

int main(void)
{
	scanf("%lld", &n);
	scanf("%lld", &k);
	
	for(ll i = 1 ; i <= n ; i++)
	{
		scanf("%lld %lld", &a[i].fi.se, &a[i].fi.fi);
		
		if(a[i].fi.fi == -1)
			a[i].fi.fi = 1000000000;
		
		won[i] = a[i].fi;
		a[i].se = i;
	}
	
	sort(a + 1, a + 1 + n);
	
	for(ll i = 1 ; i <= k ; i++)
		chk[a[i].se] = 2;
	
	for(ll i = 0 ; i <= k ; i++)
	{
		vector<ll> vec;
		vector< pair< pair<ll, ll>, ll> > vec2;
		ld minn = INF;
		ll gap1, gap2;
		ll A = i, B = k - i;
		ll mini = INF, ww = 0;
		ll ad = 0, sb = 0;
		
		ans = min(ans, calc());
		
		for(ll j = 1 ; j <= n ; j++)
		{
			if(chk[a[j].se] == 2)
				vec.push_back(j);
			
			else if(!chk[a[j].se])
			{
				if(mini > a[j].fi.se)
				{
					mini = a[j].fi.se;
					ww = j;
				}
			}
		}
		
		for(auto &j : vec)
		{
			chk[a[j].se] = 0;
			chk[a[j].se] = 1;
			
			ld gappp = calc();
			
			if(minn > gappp)
			{
				minn = gappp;
				ad = a[j].se;
				sb = a[j].se;
			}
			
			chk[a[j].se] = 2;
			
			if(ww)
			{
				chk[a[j].se] = 0;
				chk[a[ww].se] = 1;
				
				gappp = calc();
				
				if(minn > gappp)
				{
					minn = gappp;
					ad = a[ww].se;
					sb = a[j].se;
				}
				
				chk[a[j].se] = 2;
				chk[a[ww].se] = 0;
			}
		}
		
		chk[sb] = 0;
		chk[ad] = 1;
	}
	
	ans = min(ans, calc());
	
	printf("%.10Lf", ans);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:74:6: warning: unused variable 'gap1' [-Wunused-variable]
   74 |   ll gap1, gap2;
      |      ^~~~
Main.cpp:74:12: warning: unused variable 'gap2' [-Wunused-variable]
   74 |   ll gap1, gap2;
      |            ^~~~
Main.cpp:75:6: warning: unused variable 'A' [-Wunused-variable]
   75 |   ll A = i, B = k - i;
      |      ^
Main.cpp:75:13: warning: unused variable 'B' [-Wunused-variable]
   75 |   ll A = i, B = k - i;
      |             ^
Main.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%lld", &n);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%lld", &k);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   scanf("%lld %lld", &a[i].fi.se, &a[i].fi.fi);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 324 KB Output is correct
6 Correct 34 ms 308 KB Output is correct
7 Correct 179 ms 308 KB Output is correct
8 Correct 553 ms 316 KB Output is correct
9 Correct 655 ms 316 KB Output is correct
10 Correct 455 ms 316 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 324 KB Output is correct
6 Correct 34 ms 308 KB Output is correct
7 Correct 179 ms 308 KB Output is correct
8 Correct 553 ms 316 KB Output is correct
9 Correct 655 ms 316 KB Output is correct
10 Correct 455 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 82 ms 308 KB Output is correct
13 Correct 98 ms 312 KB Output is correct
14 Correct 92 ms 304 KB Output is correct
15 Correct 1000 ms 316 KB Output is correct
16 Correct 1022 ms 312 KB Output is correct
17 Correct 676 ms 316 KB Output is correct
18 Correct 1605 ms 320 KB Output is correct
19 Correct 1453 ms 316 KB Output is correct
20 Correct 923 ms 448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Incorrect 0 ms 212 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1614 ms 316 KB Output is correct
2 Correct 1556 ms 320 KB Output is correct
3 Correct 1549 ms 316 KB Output is correct
4 Correct 1651 ms 320 KB Output is correct
5 Correct 1575 ms 320 KB Output is correct
6 Correct 1576 ms 448 KB Output is correct
7 Correct 1534 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 5 ms 324 KB Output is correct
6 Correct 34 ms 308 KB Output is correct
7 Correct 179 ms 308 KB Output is correct
8 Correct 553 ms 316 KB Output is correct
9 Correct 655 ms 316 KB Output is correct
10 Correct 455 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 82 ms 308 KB Output is correct
13 Correct 98 ms 312 KB Output is correct
14 Correct 92 ms 304 KB Output is correct
15 Correct 1000 ms 316 KB Output is correct
16 Correct 1022 ms 312 KB Output is correct
17 Correct 676 ms 316 KB Output is correct
18 Correct 1605 ms 320 KB Output is correct
19 Correct 1453 ms 316 KB Output is correct
20 Correct 923 ms 448 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 0 ms 212 KB Output is correct
35 Incorrect 0 ms 212 KB Output isn't correct
36 Halted 0 ms 0 KB -