# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
804534 | MilosMilutinovic | Let's Win the Election (JOI22_ho_t3) | C++14 | 310 ms | 4308 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ldb double
const int MAX = 505;
const ldb inf = (ldb) 1e9;
int n, m, a[MAX], b[MAX];
int order[MAX];
ldb dp[2][MAX][MAX];
bool cmp(int i, int j) {
int vi = (b[i] == -1 ? (int) 1e9 : b[i]);
int vj = (b[j] == -1 ? (int) 1e9 : b[j]);
return vi < vj;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i], &b[i]);
}
for (int i = 1; i <= n; i++) {
order[i] = i;
}
sort(order + 1, order + 1 + n, cmp);
for (int k = 0; k < 2; k++) {
for (int i = 0; i <= n + 1; i++) {
for (int j = 0; j <= n; j++) {
dp[k][i][j] = inf;
}
}
}
dp[0][1][0] = 0;
for (int _i = 1; _i <= n; _i++) {
int i = order[_i];
int f = (_i % 2), p = 1 - f;
for (int j = 0; j <= n + 1; j++) {
for (int k = 0; k <= n; k++) {
dp[f][j][k] = dp[p][j][k];
}
}
if (b[i] != -1) {
for (int j = 1; j <= n; j++) {
for (int k = 0; k < n; k++) {
dp[f][j + 1][k + 1] = min(dp[f][j + 1][k + 1], dp[p][j][k] + ((ldb) (b[i] + 0.000) / (ldb) (j + 0.000)));
}
}
}
for (int j = 1; j <= n + 1; j++) {
for (int k = 0; k < n; k++) {
dp[f][j][k + 1] = min(dp[f][j][k + 1], dp[p][j][k] + ((ldb) (a[i] + 0.000) / (ldb) (j + 0.000)));
}
}
for (int j = 0; j <= n + 1; j++) {
for (int k = 0; k <= n; k++) {
dp[p][j][k] = dp[f][j][k];
}
}
}
double ans = inf;
for (int k = 0; k < 2; k++) {
for (int i = 1; i <= n + 1; i++) {
ans = min(ans, dp[k][i][m]);
}
}
printf("%.5lf\n", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |