답안 #527705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527705 2022-02-18T04:15:30 Z 8e7 Let's Win the Election (JOI22_ho_t3) C++17
67 / 100
2500 ms 2308 KB
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
	while (l != r) cout << *l << " ", l++;
	cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 505
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
pii a[maxn];
const double inf = 1e9;
double dp[maxn][maxn];
int main() {
	io
	int n, k;
	cin >> n >> k;

	for (int i = 0;i < n;i++) {
		cin >> a[i].ff >> a[i].ss; 	
		if (a[i].ss == -1) a[i].ss = 1<<30;
	}
	sort(a, a + n, [&] (pii x, pii y){return (x.ss == y.ss ? x.ff > y.ff : x.ss < y.ss);});
	double ans = 1e9;
	for (int i = 0;i <= k;i++) {
		vector<pii> b;
		for (int j = n-1;j >= i;j--) {
			b.push_back(a[j]);
		}
		sort(b.begin(), b.end());
		vector<pii> v;
		for (int j = 0;j < i;j++) v.push_back(a[j]);
		for (int j = 0;j < k - i;j++) v.push_back(b[j]);
		sort(v.begin(), v.end(), [&](pii x, pii y){return x.ss < y.ss;});

		for (int c = 0;c < k;c++) {
			double tmp = 0;
			for (int j = 0;j < k;j++) tmp += double(v[j].ff) / (c + 1);
			for (int x = 0;x <= k;x++) {
				for (int y = 0;y <= k;y++) dp[x][y] = inf;
			}
			dp[0][0] = 0;
			for (int x = 1;x <= k;x++) {
				for (int y = 0;y <= k;y++) {
					dp[x][y] = dp[x-1][y];
					if (y) {
						dp[x][y] = min(dp[x][y], dp[x-1][y-1] - (double(v[x-1].ff)/(c+1)) + (double)v[x-1].ss/y);
					}
				}
			}
			//debug(i, cur, tmp);
			debug(dp[k][c], tmp);
			ans = min(ans, dp[k][c] + tmp);
		}
		if (k == n) break;
	}
	cout << fixed << setprecision(10) << ans << "\n";
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:12:20: warning: statement has no effect [-Wunused-value]
   12 | #define debug(...) 0
      |                    ^
Main.cpp:62:4: note: in expansion of macro 'debug'
   62 |    debug(dp[k][c], tmp);
      |    ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 28 ms 460 KB Output is correct
6 Correct 921 ms 820 KB Output is correct
7 Execution timed out 2583 ms 1228 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 28 ms 460 KB Output is correct
6 Correct 921 ms 820 KB Output is correct
7 Execution timed out 2583 ms 1228 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 272 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 272 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 272 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 0 ms 332 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 336 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 1 ms 332 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 4 ms 332 KB Output is correct
44 Correct 5 ms 332 KB Output is correct
45 Correct 25 ms 460 KB Output is correct
46 Correct 30 ms 460 KB Output is correct
47 Correct 68 ms 580 KB Output is correct
48 Correct 67 ms 564 KB Output is correct
49 Correct 148 ms 624 KB Output is correct
50 Correct 161 ms 620 KB Output is correct
51 Correct 5 ms 716 KB Output is correct
52 Correct 6 ms 716 KB Output is correct
53 Correct 72 ms 556 KB Output is correct
54 Correct 69 ms 560 KB Output is correct
55 Correct 67 ms 556 KB Output is correct
56 Correct 69 ms 460 KB Output is correct
57 Correct 68 ms 460 KB Output is correct
58 Correct 74 ms 560 KB Output is correct
59 Correct 79 ms 560 KB Output is correct
60 Correct 72 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 443 ms 2288 KB Output is correct
2 Correct 472 ms 2292 KB Output is correct
3 Correct 432 ms 2292 KB Output is correct
4 Correct 419 ms 2292 KB Output is correct
5 Correct 438 ms 2308 KB Output is correct
6 Correct 430 ms 2292 KB Output is correct
7 Correct 462 ms 2300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 28 ms 460 KB Output is correct
6 Correct 921 ms 820 KB Output is correct
7 Execution timed out 2583 ms 1228 KB Time limit exceeded
8 Halted 0 ms 0 KB -