답안 #1084634

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1084634 2024-09-06T15:12:19 Z GasmaskChan Let's Win the Election (JOI22_ho_t3) C++17
21 / 100
216 ms 4444 KB
#include <bits/stdc++.h>

using namespace std;
#define int long long

const int MAX = 5e2 + 5;

int n, k;
pair<int, int> state[MAX];
double f[2][MAX][MAX];

namespace SUB12 {
  bool realko() {
    return n > 7;
  }
  
  void solve() {
      sort(state + 1, state + n + 1, [](const pair<int, int> &a, const pair<int, int> &b) -> bool {
          if (a.second != -1 && b.second != -1) {
              return 2 * a.second - a.first < 2 * b.second - b.first;
          }
          return a.second > b.second;
      });
   
      for (int i = 0; i < 2; i++) {
          for (int j = 0; j <= n + 1; j++) {
              for (int z = 0; z <= k; z++) {
                  f[i & 1][j][z] = 1e9;
              }
          }
      }
   
      f[0][1][0] = 0.0;
   
      for (int i = 1; i <= n; i++) {
   
          for (int j = 1; j <= i + 1; j++) {
              for (int z = 0; z <= k; z++) {
                  f[i & 1][j][z] = 1e9;
              }
          }
   
          for (int j = 1; j <= i + 1; j++) {
              for (int z = 0; z <= k; z++) {
                  f[i & 1][j][z] = f[(i - 1) & 1][j][z];
   
                  if (z) f[i & 1][j][z] = min(f[i & 1][j][z], f[(i - 1) & 1][j][z - 1] + (1.0 * state[i].first / j));
   
                  if (j > 1 && z && state[i].second != -1) {
                      f[i & 1][j][z] = min(f[i & 1][j][z], f[(i - 1) & 1][j - 1][z - 1] + (1.0 * state[i].second / (j - 1)));
                  }
              }
          }
      }
   
      double ans = 1e9;
      for (int j = 1; j <= n + 1; j++) {
          ans = min(ans, f[n & 1][j][k]);
      }
   
      cout << fixed << ans;
      exit(0);
  }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> state[i].first >> state[i].second;

    if (SUB12::realko()) SUB12::solve();

    vector<int> p(n);
    iota(p.begin(), p.end(), 1);
    
    double ans = 1e9;
    do {
        
        for (int i = 0; i < 2; i++) {
            for (int j = 0; j <= n + 1; j++) {
                for (int z = 0; z <= k; z++) {
                    f[i & 1][j][z] = 1e9;
                }
            }
        }
    
        f[0][1][0] = 0.0;
    
        for (int i = 1; i <= n; i++) {
            int cur = p[i - 1];
    
            for (int j = 1; j <= i + 1; j++) {
                for (int z = 0; z <= k; z++) {
                    f[i & 1][j][z] = 1e9;
                }
            }
    
            for (int j = 1; j <= i + 1; j++) {
                for (int z = 0; z <= k; z++) {
                    f[i & 1][j][z] = f[(i - 1) & 1][j][z];
    
                    if (z) f[i & 1][j][z] = min(f[i & 1][j][z], f[(i - 1) & 1][j][z - 1] + (1.0 * state[cur].first / j));
    
                    if (j > 1 && z && state[cur].second != -1) {
                        f[i & 1][j][z] = min(f[i & 1][j][z], f[(i - 1) & 1][j - 1][z - 1] + (1.0 * state[cur].second / (j - 1)));
                    }
                }
            }
        }
    
        double res = 1e9;
        for (int j = 1; j <= n + 1; j++) {
            res = min(res, f[n & 1][j][k]);
        }
      
        if (res - ans < 0) {
          ans = res;
          // cout << fixed << ans << ' ';
          // for (int i : p) cout << i << ' ';
          // cout << '\n';
        }
    } while (next_permutation(p.begin(), p.end()));

    cout << fixed << ans;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 14 ms 4184 KB Output is correct
6 Correct 34 ms 4188 KB Output is correct
7 Correct 62 ms 4184 KB Output is correct
8 Correct 92 ms 4188 KB Output is correct
9 Correct 125 ms 4420 KB Output is correct
10 Correct 87 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 14 ms 4184 KB Output is correct
6 Correct 34 ms 4188 KB Output is correct
7 Correct 62 ms 4184 KB Output is correct
8 Correct 92 ms 4188 KB Output is correct
9 Correct 125 ms 4420 KB Output is correct
10 Correct 87 ms 4188 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 69 ms 4408 KB Output is correct
13 Correct 49 ms 4188 KB Output is correct
14 Correct 40 ms 4188 KB Output is correct
15 Correct 151 ms 4444 KB Output is correct
16 Correct 107 ms 4420 KB Output is correct
17 Correct 87 ms 4192 KB Output is correct
18 Correct 208 ms 4188 KB Output is correct
19 Correct 151 ms 4420 KB Output is correct
20 Correct 120 ms 4420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 4 ms 680 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 4 ms 680 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Incorrect 1 ms 604 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 3 ms 460 KB Output is correct
5 Correct 4 ms 348 KB Output is correct
6 Correct 4 ms 344 KB Output is correct
7 Correct 4 ms 348 KB Output is correct
8 Correct 4 ms 680 KB Output is correct
9 Correct 3 ms 540 KB Output is correct
10 Correct 3 ms 348 KB Output is correct
11 Correct 4 ms 348 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 4 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Incorrect 1 ms 604 KB Output isn't correct
18 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 216 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 460 KB Output is correct
5 Correct 14 ms 4184 KB Output is correct
6 Correct 34 ms 4188 KB Output is correct
7 Correct 62 ms 4184 KB Output is correct
8 Correct 92 ms 4188 KB Output is correct
9 Correct 125 ms 4420 KB Output is correct
10 Correct 87 ms 4188 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 69 ms 4408 KB Output is correct
13 Correct 49 ms 4188 KB Output is correct
14 Correct 40 ms 4188 KB Output is correct
15 Correct 151 ms 4444 KB Output is correct
16 Correct 107 ms 4420 KB Output is correct
17 Correct 87 ms 4192 KB Output is correct
18 Correct 208 ms 4188 KB Output is correct
19 Correct 151 ms 4420 KB Output is correct
20 Correct 120 ms 4420 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 348 KB Output is correct
23 Correct 2 ms 348 KB Output is correct
24 Correct 3 ms 460 KB Output is correct
25 Correct 4 ms 348 KB Output is correct
26 Correct 4 ms 344 KB Output is correct
27 Correct 4 ms 348 KB Output is correct
28 Correct 4 ms 680 KB Output is correct
29 Correct 3 ms 540 KB Output is correct
30 Correct 3 ms 348 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 3 ms 344 KB Output is correct
33 Correct 3 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Incorrect 1 ms 604 KB Output isn't correct
38 Halted 0 ms 0 KB -