답안 #718963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
718963 2023-04-05T07:52:57 Z Kalashnikov Let's Win the Election (JOI22_ho_t3) C++17
0 / 100
1419 ms 994588 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;
			}
		}
	}
	for(int i = 0; i <= n; i ++) dp[i][0][0] = 0;
	double ans = INF;
	for(int l = 0; l <= n; l ++) { // в конце сторонников
		for(int i = 0; i < n; i ++) {
			for(int j = 0; j <= i; j ++) {
				mini(dp[i+1][j][l], dp[i][j][l]);
				mini(dp[i+1][j+1][l], dp[i][j][l] + a[i+1]/double(l+1));
				if(i == j)
				for(int x = 0; x <= min(j, l); 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(l+1));
					if(b[i+1] != inf)
						mini(dp[i+1][j+1][x+1], dp[i][j][x] + b[i+1]/double(x+1));
				}
			}
		}
		ans = min(ans, dp[n][k][l]);
	}
	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:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   69 | main() {
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Incorrect 1 ms 596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Incorrect 1 ms 596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Incorrect 1 ms 596 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1419 ms 994588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -