Submission #692994

# Submission time Handle Problem Language Result Execution time Memory
692994 2023-02-02T08:26:50 Z bdl Let's Win the Election (JOI22_ho_t3) C++17
10 / 100
192 ms 2268 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <array>
#include <iostream>
using namespace std;

#define ar array

const int N = 500, INF = 1e9;
const long long INF_LL = 1e18;

int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  static ar<int, 2> a[N];
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a[i][1], &a[i][0]);
    if (a[i][0] == -1)
      a[i][0] = INF;
  }
  sort(a, a + n);
  static long long sm[N + 1][N + 1];
  for (int i = n - 1; i >= 0; i--)
    for (int j = 1; j <= n - i; j++)
      sm[i][j] = min(a[i][1] + sm[i + 1][j - 1], j != n - i ? sm[i + 1][j] : INF_LL);
  double ans = sm[0][k];
  for (int t = 1; t <= k; t++) {
    static double f[N + 1];
    for (int i = 1; i <= t; i++)
      f[i] = INF_LL;
    f[0] = 0;
    for (int i = 0; i < n; i++) {
      for (int j = t; j >= 0; j--)
        f[j] = min(f[j] + (double) a[i][1] / (j + 1), j == 0 ? INF_LL : f[j - 1] + (double) a[i][0] / j);
      if (i >= t - 1 && k - i > 0)
        ans = min(ans, f[t] + (double) sm[i + 1][k - i - 1] / (t + 1));
    }
  }
  printf("%.4lf\n", ans);
  return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:16:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
Main.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%d", &k);
      |   ~~~~~^~~~~~~~~~
Main.cpp:20:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     scanf("%d%d", &a[i][1], &a[i][0]);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 14 ms 2264 KB Output is correct
7 Correct 48 ms 2260 KB Output is correct
8 Correct 106 ms 2228 KB Output is correct
9 Correct 191 ms 2228 KB Output is correct
10 Correct 92 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 14 ms 2264 KB Output is correct
7 Correct 48 ms 2260 KB Output is correct
8 Correct 106 ms 2228 KB Output is correct
9 Correct 191 ms 2228 KB Output is correct
10 Correct 92 ms 2260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 2264 KB Output is correct
13 Correct 19 ms 2268 KB Output is correct
14 Correct 18 ms 2260 KB Output is correct
15 Correct 103 ms 2260 KB Output is correct
16 Correct 100 ms 2260 KB Output is correct
17 Correct 94 ms 2260 KB Output is correct
18 Correct 186 ms 2260 KB Output is correct
19 Correct 184 ms 2260 KB Output is correct
20 Correct 183 ms 2260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 308 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Incorrect 1 ms 340 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 192 ms 2248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 3 ms 2260 KB Output is correct
6 Correct 14 ms 2264 KB Output is correct
7 Correct 48 ms 2260 KB Output is correct
8 Correct 106 ms 2228 KB Output is correct
9 Correct 191 ms 2228 KB Output is correct
10 Correct 92 ms 2260 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 20 ms 2264 KB Output is correct
13 Correct 19 ms 2268 KB Output is correct
14 Correct 18 ms 2260 KB Output is correct
15 Correct 103 ms 2260 KB Output is correct
16 Correct 100 ms 2260 KB Output is correct
17 Correct 94 ms 2260 KB Output is correct
18 Correct 186 ms 2260 KB Output is correct
19 Correct 184 ms 2260 KB Output is correct
20 Correct 183 ms 2260 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 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 0 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 0 ms 308 KB Output is correct
28 Correct 0 ms 340 KB Output is correct
29 Incorrect 1 ms 340 KB Output isn't correct
30 Halted 0 ms 0 KB -