답안 #747905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
747905 2023-05-25T07:24:58 Z MilosMilutinovic Let's Win the Election (JOI22_ho_t3) C++14
10 / 100
219 ms 4268 KB
#include <bits/stdc++.h>
using namespace std;
const int N = 505;
int n, k, a[N], b[N], ord[N];
double dp[N][N], ndp[N][N];
bool cmp(int i, int j) {
    int si = a[i] + (b[i] == -1 ? 1e8 : b[i]);
    int sj = a[j] + (b[j] == -1 ? 1e8 : b[j]);
    if (si != sj) return si < sj;
    else return a[i] < a[j];
}
int main() {
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]), b[i] = (b[i] == -1 ? -1 : b[i] - a[i]);
    for (int i = 1; i <= n; i++) ord[i] = i;
    sort(ord + 1, ord + n + 1, cmp);
    for (int i = 0; i <= n; i++)
        for (int j = 0; j <= n; j++)
            dp[i][j] = 1e9;
    dp[0][1] = 0;
    for (int _i = 1; _i <= n; _i++) {
        int i = ord[_i];
        for (int j = 0; j <= n; j++)
            for (int l = 0; l <= n; l++)
                ndp[j][l] = dp[j][l];
        for (int j = 0; j <= n; j++) {
            for (int l = 0; l <= n; l++) {
                if (ndp[j][l] > 1e8) continue;
                dp[j + 1][l] = min(dp[j + 1][l], ndp[j][l] + (double) (a[i] + 0.0) / l);
                if (b[i] != -1) dp[j + 1][l + 1] = min(dp[j + 1][l + 1], ndp[j][l] + (double) (a[i] + b[i] + 0.0) / l);
            }
        }
    }
    double ans = 1e9;
    for (int i = 0; i <= n; i++) ans = min(ans, dp[k][i]);
    printf("%.4lf", ans);
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:14:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     for (int i = 1; i <= n; i++) scanf("%d%d", &a[i], &b[i]), b[i] = (b[i] == -1 ? -1 : b[i] - a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 133 ms 4260 KB Output is correct
6 Correct 137 ms 4252 KB Output is correct
7 Correct 141 ms 4268 KB Output is correct
8 Correct 147 ms 4256 KB Output is correct
9 Correct 149 ms 4256 KB Output is correct
10 Correct 131 ms 4144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 133 ms 4260 KB Output is correct
6 Correct 137 ms 4252 KB Output is correct
7 Correct 141 ms 4268 KB Output is correct
8 Correct 147 ms 4256 KB Output is correct
9 Correct 149 ms 4256 KB Output is correct
10 Correct 131 ms 4144 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 205 ms 4268 KB Output is correct
13 Correct 158 ms 4256 KB Output is correct
14 Correct 161 ms 4180 KB Output is correct
15 Correct 214 ms 4256 KB Output is correct
16 Correct 192 ms 4180 KB Output is correct
17 Correct 151 ms 4252 KB Output is correct
18 Correct 219 ms 4180 KB Output is correct
19 Correct 182 ms 4260 KB Output is correct
20 Correct 156 ms 4256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 304 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 207 ms 4180 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 133 ms 4260 KB Output is correct
6 Correct 137 ms 4252 KB Output is correct
7 Correct 141 ms 4268 KB Output is correct
8 Correct 147 ms 4256 KB Output is correct
9 Correct 149 ms 4256 KB Output is correct
10 Correct 131 ms 4144 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 205 ms 4268 KB Output is correct
13 Correct 158 ms 4256 KB Output is correct
14 Correct 161 ms 4180 KB Output is correct
15 Correct 214 ms 4256 KB Output is correct
16 Correct 192 ms 4180 KB Output is correct
17 Correct 151 ms 4252 KB Output is correct
18 Correct 219 ms 4180 KB Output is correct
19 Correct 182 ms 4260 KB Output is correct
20 Correct 156 ms 4256 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 0 ms 304 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Halted 0 ms 0 KB -