답안 #794844

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794844 2023-07-27T01:02:42 Z gun_gan Let's Win the Election (JOI22_ho_t3) C++17
61 / 100
2500 ms 499356 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const int MX = 505;
 
int N, K;
int a[MX], b[MX];
double dp[MX][MX][MX];
 
vector<pair<int, int>> v;

double memo[MX];
 
double f(int x) {
      if(memo[x] != -1) return memo[x];

      for(int i = 0; i <= N; i++)
            for(int j = 0; j <= min(i, K); j++)
                  for(int k = 0; k <= min(i, x); k++)
                        dp[i][j][k] = 1e9;
       
      dp[0][0][0] = 0;
      for(int i = 0; i < N; i++) {
            for(int j = 0; j <= min(i, K); j++) { // votes
                  for(int k = 0; k <= min(i, x); k++) { // num of collaborator
                        if(dp[i][j][k] == 1e9) continue;
 
                        // skip
                        dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
 
                        // ambil vote
                        dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (double) v[i].second / (x + 1));
                        
                        // ambil collaborator
                        if(v[i].first != 1e9) 
                              dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (double) v[i].first / (k + 1));
                  }
            }
      }
 
      return memo[x] = dp[N][K][x];
}
 
int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);

      for(int i = 0; i < MX; i++) memo[i] = -1;
 
      cin >> N >> K;
 
      int tot = 0;
      for(int i = 1; i <= N; i++) {
            cin >> a[i] >> b[i];
            if(b[i] != -1) tot++;
            else b[i] = 1e9;
            v.push_back({b[i], a[i]});
      }
 
      sort(v.begin(), v.end());
 
      double ans = 1e9;
      int l = 0, r = min(K, tot);
 
      while(r - l > 1) {
            int mid = (l + r) >> 1;
            if(f(mid) > f(mid + 1)) 
                  l = mid;
            else 
                  r = mid;
      } 
 
      cout << fixed << setprecision(15) << min(f(l), f(l + 1)) << '\n';
 
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:62:14: warning: unused variable 'ans' [-Wunused-variable]
   62 |       double ans = 1e9;
      |              ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 36 ms 99808 KB Output is correct
6 Correct 74 ms 221716 KB Output is correct
7 Correct 125 ms 375604 KB Output is correct
8 Correct 169 ms 467772 KB Output is correct
9 Correct 166 ms 498436 KB Output is correct
10 Correct 147 ms 454328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 36 ms 99808 KB Output is correct
6 Correct 74 ms 221716 KB Output is correct
7 Correct 125 ms 375604 KB Output is correct
8 Correct 169 ms 467772 KB Output is correct
9 Correct 166 ms 498436 KB Output is correct
10 Correct 147 ms 454328 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 675 ms 257856 KB Output is correct
13 Correct 530 ms 257852 KB Output is correct
14 Correct 360 ms 257656 KB Output is correct
15 Correct 2324 ms 455228 KB Output is correct
16 Correct 1557 ms 455088 KB Output is correct
17 Correct 818 ms 454660 KB Output is correct
18 Execution timed out 2604 ms 499356 KB Time limit exceeded
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 724 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1236 KB Output is correct
32 Correct 1 ms 1236 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 1 ms 1228 KB Output is correct
37 Correct 1 ms 1236 KB Output is correct
38 Correct 1 ms 1236 KB Output is correct
39 Correct 1 ms 1236 KB Output is correct
40 Correct 1 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 0 ms 468 KB Output is correct
7 Correct 0 ms 468 KB Output is correct
8 Correct 0 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 0 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 0 ms 468 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 468 KB Output is correct
16 Correct 0 ms 724 KB Output is correct
17 Correct 1 ms 980 KB Output is correct
18 Correct 1 ms 1108 KB Output is correct
19 Correct 1 ms 1236 KB Output is correct
20 Correct 1 ms 1236 KB Output is correct
21 Correct 1 ms 1236 KB Output is correct
22 Correct 1 ms 1236 KB Output is correct
23 Correct 1 ms 1236 KB Output is correct
24 Correct 1 ms 1236 KB Output is correct
25 Correct 1 ms 1236 KB Output is correct
26 Correct 1 ms 1236 KB Output is correct
27 Correct 1 ms 1236 KB Output is correct
28 Correct 1 ms 1236 KB Output is correct
29 Correct 1 ms 1236 KB Output is correct
30 Correct 1 ms 1236 KB Output is correct
31 Correct 1 ms 1236 KB Output is correct
32 Correct 1 ms 1236 KB Output is correct
33 Correct 1 ms 1236 KB Output is correct
34 Correct 1 ms 1236 KB Output is correct
35 Correct 1 ms 1236 KB Output is correct
36 Correct 1 ms 1228 KB Output is correct
37 Correct 1 ms 1236 KB Output is correct
38 Correct 1 ms 1236 KB Output is correct
39 Correct 1 ms 1236 KB Output is correct
40 Correct 1 ms 1236 KB Output is correct
41 Correct 3 ms 6868 KB Output is correct
42 Correct 3 ms 6868 KB Output is correct
43 Correct 6 ms 11544 KB Output is correct
44 Correct 7 ms 11476 KB Output is correct
45 Correct 10 ms 16204 KB Output is correct
46 Correct 10 ms 16136 KB Output is correct
47 Correct 11 ms 18672 KB Output is correct
48 Correct 13 ms 18736 KB Output is correct
49 Correct 17 ms 20332 KB Output is correct
50 Correct 14 ms 20336 KB Output is correct
51 Correct 17 ms 21092 KB Output is correct
52 Correct 18 ms 21092 KB Output is correct
53 Correct 10 ms 18644 KB Output is correct
54 Correct 12 ms 18728 KB Output is correct
55 Correct 13 ms 18664 KB Output is correct
56 Correct 14 ms 18732 KB Output is correct
57 Correct 16 ms 18740 KB Output is correct
58 Correct 13 ms 18644 KB Output is correct
59 Correct 14 ms 18644 KB Output is correct
60 Correct 14 ms 18736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2431 ms 499344 KB Output is correct
2 Execution timed out 2506 ms 499352 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 36 ms 99808 KB Output is correct
6 Correct 74 ms 221716 KB Output is correct
7 Correct 125 ms 375604 KB Output is correct
8 Correct 169 ms 467772 KB Output is correct
9 Correct 166 ms 498436 KB Output is correct
10 Correct 147 ms 454328 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 675 ms 257856 KB Output is correct
13 Correct 530 ms 257852 KB Output is correct
14 Correct 360 ms 257656 KB Output is correct
15 Correct 2324 ms 455228 KB Output is correct
16 Correct 1557 ms 455088 KB Output is correct
17 Correct 818 ms 454660 KB Output is correct
18 Execution timed out 2604 ms 499356 KB Time limit exceeded
19 Halted 0 ms 0 KB -