Submission #718920

# Submission time Handle Problem Language Result Execution time Memory
718920 2023-04-05T07:20:30 Z Kalashnikov Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
595 ms 994628 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 500+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int a[N], b[N];

double dp[N][N][N];

void mini(double &a, double b) {
	a = min(a, b);
}

void solve(int tc) {
	int n , k;
	cin >> n >> k;
	vector<pair<int,int>> vec;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i] >> b[i];
		if(b[i] == -1) b[i] = inf;
		vec.push_back({b[i] , a[i]});
	}
	sort(all(vec));
	for(int i = 1; i <= n; i ++) {
		a[i] = vec[i-1].S;
		b[i] = vec[i-1].F;
	}
	for(int i = 0; i <= n; i ++) {
		for(int j = 0; j <= n; j ++) {
			for(int k = 0; k <= n; k ++) {
				dp[i][j][k] = INF;
			}
		}
	}
	double ans = INF;
	dp[0][0][0] = 0;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j <= i; j ++) {
			for(int x = 0; x <= i; x ++) {
				mini(dp[i+1][j][x], dp[i][j][x]);
				mini(dp[i+1][j+1][x], dp[i][j][x] + a[i+1]/double(x+1));
				if(b[i+1] != inf)
					mini(dp[i+1][j+1][x+1], dp[i][j][x] + b[i+1]/double(x+1));
			}
		}
	}
	for(int x = 0; x <= n; x ++) {
		ans = min(ans, dp[n][k][x]);
	}
	cout << fixed << setprecision(6) << ans;
}
/*
*/
main() {
    ios;
    int tt = 1 , tc = 0;
    // cin >> tt;
    while(tt --) {
        solve(++tc);
    }
    return 0;
}

Compilation message

Main.cpp:63:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   63 | main() {
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 515 ms 994536 KB Output is correct
6 Correct 513 ms 994608 KB Output is correct
7 Correct 495 ms 994628 KB Output is correct
8 Correct 512 ms 994464 KB Output is correct
9 Correct 485 ms 994508 KB Output is correct
10 Correct 489 ms 994540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 515 ms 994536 KB Output is correct
6 Correct 513 ms 994608 KB Output is correct
7 Correct 495 ms 994628 KB Output is correct
8 Correct 512 ms 994464 KB Output is correct
9 Correct 485 ms 994508 KB Output is correct
10 Correct 489 ms 994540 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 595 ms 994584 KB Output is correct
13 Correct 523 ms 994508 KB Output is correct
14 Correct 487 ms 994524 KB Output is correct
15 Correct 536 ms 994568 KB Output is correct
16 Correct 496 ms 994432 KB Output is correct
17 Correct 483 ms 994616 KB Output is correct
18 Correct 551 ms 994540 KB Output is correct
19 Correct 510 ms 994488 KB Output is correct
20 Correct 484 ms 994480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Incorrect 1 ms 496 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Incorrect 1 ms 496 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 592 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 1 ms 596 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Incorrect 1 ms 496 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 576 ms 994532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 0 ms 340 KB Output is correct
5 Correct 515 ms 994536 KB Output is correct
6 Correct 513 ms 994608 KB Output is correct
7 Correct 495 ms 994628 KB Output is correct
8 Correct 512 ms 994464 KB Output is correct
9 Correct 485 ms 994508 KB Output is correct
10 Correct 489 ms 994540 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 595 ms 994584 KB Output is correct
13 Correct 523 ms 994508 KB Output is correct
14 Correct 487 ms 994524 KB Output is correct
15 Correct 536 ms 994568 KB Output is correct
16 Correct 496 ms 994432 KB Output is correct
17 Correct 483 ms 994616 KB Output is correct
18 Correct 551 ms 994540 KB Output is correct
19 Correct 510 ms 994488 KB Output is correct
20 Correct 484 ms 994480 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 592 KB Output is correct
23 Correct 1 ms 588 KB Output is correct
24 Correct 1 ms 596 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 1 ms 596 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 1 ms 596 KB Output is correct
29 Incorrect 1 ms 496 KB Output isn't correct
30 Halted 0 ms 0 KB -