Submission #598822

# Submission time Handle Problem Language Result Execution time Memory
598822 2022-07-19T06:08:42 Z denniskim Let's Win the Election (JOI22_ho_t3) C++17
56 / 100
2500 ms 1048576 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<ll, ll> a[510];
ld ans = INF;
ll chk[510];
ld dp[510][510][510];
ld gap[510];
ll l, r;

ld query(ll i)
{
	if(gap[i])
		return gap[i];
	
	for(ll j = 0 ; j <= n ; j++)
	{
		for(ll o = 0 ; o <= k ; o++)
		{
			for(ll oo = 0 ; oo <= i ; oo++)
				dp[j][o][oo] = 10000000;
		}
	}
	
	dp[0][0][0] = 0;
	
	for(ll j = 1 ; j <= n ; j++)
	{
		for(ll o = 0 ; o <= k ; o++)
		{
			for(ll oo = 0 ; oo <= i ; oo++)
			{
				dp[j][o][oo] = min(dp[j][o][oo], dp[j - 1][o][oo]);
				
				if(o >= 1)
					dp[j][o][oo] = min(dp[j][o][oo], dp[j - 1][o - 1][oo] + (ld)a[j].se / (ld)(i + 1));
				
				if(o >= 1 && oo >= 1)
					dp[j][o][oo] = min(dp[j][o][oo], dp[j - 1][o - 1][oo - 1] + (ld)a[j].fi / (ld)oo);
			}
		}
	}
	
	return gap[i] = dp[n][k][i];
}

int main(void)
{
	scanf("%lld", &n);
	scanf("%lld", &k);
	
	for(ll i = 1 ; i <= n ; i++)
	{
		scanf("%lld %lld", &a[i].se, &a[i].fi);
		
		if(a[i].fi == -1)
			a[i].fi = 1000000000;
	}
	
	sort(a + 1, a + 1 + n);
	
	l = 0, r = k;
	
	while(l + 2 < r)
	{
		ll mid1 = (l * 2 + r) / 3;
		ll mid2 = (l + r * 2) / 3;
		
		if(query(mid1) <= query(mid2))
			r = mid2;
		else
			l = mid1;
	}
	
	for(ll i = l ; i <= r ; i++)
		ans = min(ans, query(i));
	
	printf("%.10Lf", ans);
	return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |  scanf("%lld", &n);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp:61:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   61 |  scanf("%lld", &k);
      |  ~~~~~^~~~~~~~~~~~
Main.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%lld %lld", &a[i].se, &a[i].fi);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 164 ms 117356 KB Output is correct
6 Correct 873 ms 336628 KB Output is correct
7 Execution timed out 2626 ms 833300 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 164 ms 117356 KB Output is correct
6 Correct 873 ms 336628 KB Output is correct
7 Execution timed out 2626 ms 833300 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1492 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 1 ms 1492 KB Output is correct
22 Correct 1 ms 1536 KB Output is correct
23 Correct 1 ms 1620 KB Output is correct
24 Correct 1 ms 1620 KB Output is correct
25 Correct 3 ms 2132 KB Output is correct
26 Correct 3 ms 2132 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 2 ms 1620 KB Output is correct
29 Correct 2 ms 1492 KB Output is correct
30 Correct 2 ms 1620 KB Output is correct
31 Correct 1 ms 1492 KB Output is correct
32 Correct 1 ms 1652 KB Output is correct
33 Correct 1 ms 1492 KB Output is correct
34 Correct 2 ms 1492 KB Output is correct
35 Correct 1 ms 1620 KB Output is correct
36 Correct 1 ms 1492 KB Output is correct
37 Correct 1 ms 1620 KB Output is correct
38 Correct 1 ms 1492 KB Output is correct
39 Correct 1 ms 1620 KB Output is correct
40 Correct 1 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
16 Correct 1 ms 724 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 1236 KB Output is correct
19 Correct 1 ms 1492 KB Output is correct
20 Correct 2 ms 1492 KB Output is correct
21 Correct 1 ms 1492 KB Output is correct
22 Correct 1 ms 1536 KB Output is correct
23 Correct 1 ms 1620 KB Output is correct
24 Correct 1 ms 1620 KB Output is correct
25 Correct 3 ms 2132 KB Output is correct
26 Correct 3 ms 2132 KB Output is correct
27 Correct 1 ms 1492 KB Output is correct
28 Correct 2 ms 1620 KB Output is correct
29 Correct 2 ms 1492 KB Output is correct
30 Correct 2 ms 1620 KB Output is correct
31 Correct 1 ms 1492 KB Output is correct
32 Correct 1 ms 1652 KB Output is correct
33 Correct 1 ms 1492 KB Output is correct
34 Correct 2 ms 1492 KB Output is correct
35 Correct 1 ms 1620 KB Output is correct
36 Correct 1 ms 1492 KB Output is correct
37 Correct 1 ms 1620 KB Output is correct
38 Correct 1 ms 1492 KB Output is correct
39 Correct 1 ms 1620 KB Output is correct
40 Correct 1 ms 1492 KB Output is correct
41 Correct 6 ms 7356 KB Output is correct
42 Correct 6 ms 7384 KB Output is correct
43 Correct 14 ms 13908 KB Output is correct
44 Correct 17 ms 13920 KB Output is correct
45 Correct 67 ms 23736 KB Output is correct
46 Correct 37 ms 23100 KB Output is correct
47 Correct 78 ms 30804 KB Output is correct
48 Correct 106 ms 31792 KB Output is correct
49 Correct 150 ms 40948 KB Output is correct
50 Correct 111 ms 39252 KB Output is correct
51 Correct 194 ms 52984 KB Output is correct
52 Correct 291 ms 54168 KB Output is correct
53 Correct 46 ms 30812 KB Output is correct
54 Correct 70 ms 30804 KB Output is correct
55 Correct 93 ms 31712 KB Output is correct
56 Correct 48 ms 30808 KB Output is correct
57 Correct 93 ms 31460 KB Output is correct
58 Correct 138 ms 32100 KB Output is correct
59 Correct 116 ms 31792 KB Output is correct
60 Correct 98 ms 31468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 541 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 164 ms 117356 KB Output is correct
6 Correct 873 ms 336628 KB Output is correct
7 Execution timed out 2626 ms 833300 KB Time limit exceeded
8 Halted 0 ms 0 KB -