답안 #879656

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879656 2023-11-27T19:47:13 Z mychecksedad Let's Win the Election (JOI22_ho_t3) C++17
100 / 100
522 ms 989896 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 502, M = 1e5+10, K = 52, MX = 30;


int n, k, sum[N][N];
array<int, 2> a[N];
double dp[N][N][N];


void solve(){
  cin >> n >> k;
  for(int i = 1; i <= n; ++i){
    cin >> a[i][1] >> a[i][0];
    if(a[i][0] == -1) a[i][0] = MOD;
  }
  sort(a+1, a+1+n);

  for(int j = 0; j <= n; ++j) sum[n+1][j] = 0;
  for(int i = n; i >= 1; --i){
    for(int j = 0; j < n - i + 1; ++j){
      sum[i][j] = min(sum[i + 1][j], j == 0 ? MOD : sum[i + 1][j - 1] + a[i][1]);
    }
    sum[i][n - i + 1] = sum[i + 1][n - i] + a[i][1];
  }
  double ans = sum[1][k];

  for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) for(int l = 0; l <= n; ++l) dp[i][j][l] = MOD;
  for(int i = 1; i <= n; ++i) dp[0][0][i] = 0;
  
  for(int l = 1; l <= k; ++l){ // collabnum
    for(int i = 1; i <= k; ++i){
      if(a[i][0] == MOD) break;

      dp[i][0][l] = dp[i - 1][0][l] + a[i][1] / (double)(l + 1);
   
      for(int j = 1; j <= min(i, l); ++j){
        dp[i][j][l] = min(dp[i - 1][j][l] + a[i][1] / (double) (l+1), dp[i - 1][j - 1][l] + a[i][0] / (double) j);
      }
    }
    for(int i = 1; i <= k; ++i)
      ans = min(ans, dp[i][l][l] + sum[i + 1][k - i] / (double) (l + 1));
  }

  // for(int i = 1; i <= n; ++i){
  //   for(int j = 0; j <= i; ++j) cout << dp[i][j].first << ' ' << dp[i][j].second << " | ";
  //   en;
  // }

  cout << fixed << setprecision(15);
  cout << ans;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:64:15: warning: unused variable 'aa' [-Wunused-variable]
   64 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 254 ms 989524 KB Output is correct
6 Correct 253 ms 989780 KB Output is correct
7 Correct 269 ms 989524 KB Output is correct
8 Correct 272 ms 989688 KB Output is correct
9 Correct 251 ms 989516 KB Output is correct
10 Correct 253 ms 989468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 254 ms 989524 KB Output is correct
6 Correct 253 ms 989780 KB Output is correct
7 Correct 269 ms 989524 KB Output is correct
8 Correct 272 ms 989688 KB Output is correct
9 Correct 251 ms 989516 KB Output is correct
10 Correct 253 ms 989468 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 257 ms 989488 KB Output is correct
13 Correct 273 ms 989712 KB Output is correct
14 Correct 254 ms 989524 KB Output is correct
15 Correct 333 ms 989708 KB Output is correct
16 Correct 314 ms 989520 KB Output is correct
17 Correct 254 ms 989776 KB Output is correct
18 Correct 504 ms 989520 KB Output is correct
19 Correct 353 ms 989804 KB Output is correct
20 Correct 260 ms 989712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 2 ms 14876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 2 ms 14876 KB Output is correct
16 Correct 5 ms 41560 KB Output is correct
17 Correct 5 ms 41564 KB Output is correct
18 Correct 4 ms 41564 KB Output is correct
19 Correct 4 ms 41564 KB Output is correct
20 Correct 5 ms 41564 KB Output is correct
21 Correct 4 ms 41564 KB Output is correct
22 Correct 4 ms 41608 KB Output is correct
23 Correct 4 ms 41564 KB Output is correct
24 Correct 5 ms 41564 KB Output is correct
25 Correct 4 ms 41564 KB Output is correct
26 Correct 5 ms 41564 KB Output is correct
27 Correct 5 ms 41564 KB Output is correct
28 Correct 5 ms 41564 KB Output is correct
29 Correct 5 ms 41564 KB Output is correct
30 Correct 5 ms 41564 KB Output is correct
31 Correct 4 ms 41568 KB Output is correct
32 Correct 5 ms 41568 KB Output is correct
33 Correct 5 ms 41568 KB Output is correct
34 Correct 5 ms 41620 KB Output is correct
35 Correct 5 ms 41428 KB Output is correct
36 Correct 5 ms 41568 KB Output is correct
37 Correct 5 ms 41564 KB Output is correct
38 Correct 5 ms 41560 KB Output is correct
39 Correct 5 ms 41816 KB Output is correct
40 Correct 4 ms 41424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14680 KB Output is correct
2 Correct 2 ms 14680 KB Output is correct
3 Correct 2 ms 14684 KB Output is correct
4 Correct 2 ms 14684 KB Output is correct
5 Correct 2 ms 14684 KB Output is correct
6 Correct 2 ms 14684 KB Output is correct
7 Correct 2 ms 14684 KB Output is correct
8 Correct 2 ms 14684 KB Output is correct
9 Correct 2 ms 14684 KB Output is correct
10 Correct 2 ms 14684 KB Output is correct
11 Correct 2 ms 14684 KB Output is correct
12 Correct 2 ms 14684 KB Output is correct
13 Correct 2 ms 14684 KB Output is correct
14 Correct 1 ms 10588 KB Output is correct
15 Correct 2 ms 14876 KB Output is correct
16 Correct 5 ms 41560 KB Output is correct
17 Correct 5 ms 41564 KB Output is correct
18 Correct 4 ms 41564 KB Output is correct
19 Correct 4 ms 41564 KB Output is correct
20 Correct 5 ms 41564 KB Output is correct
21 Correct 4 ms 41564 KB Output is correct
22 Correct 4 ms 41608 KB Output is correct
23 Correct 4 ms 41564 KB Output is correct
24 Correct 5 ms 41564 KB Output is correct
25 Correct 4 ms 41564 KB Output is correct
26 Correct 5 ms 41564 KB Output is correct
27 Correct 5 ms 41564 KB Output is correct
28 Correct 5 ms 41564 KB Output is correct
29 Correct 5 ms 41564 KB Output is correct
30 Correct 5 ms 41564 KB Output is correct
31 Correct 4 ms 41568 KB Output is correct
32 Correct 5 ms 41568 KB Output is correct
33 Correct 5 ms 41568 KB Output is correct
34 Correct 5 ms 41620 KB Output is correct
35 Correct 5 ms 41428 KB Output is correct
36 Correct 5 ms 41568 KB Output is correct
37 Correct 5 ms 41564 KB Output is correct
38 Correct 5 ms 41560 KB Output is correct
39 Correct 5 ms 41816 KB Output is correct
40 Correct 4 ms 41424 KB Output is correct
41 Correct 21 ms 199768 KB Output is correct
42 Correct 21 ms 199776 KB Output is correct
43 Correct 20 ms 199776 KB Output is correct
44 Correct 21 ms 199636 KB Output is correct
45 Correct 21 ms 199660 KB Output is correct
46 Correct 21 ms 199776 KB Output is correct
47 Correct 21 ms 199776 KB Output is correct
48 Correct 23 ms 199760 KB Output is correct
49 Correct 24 ms 200032 KB Output is correct
50 Correct 21 ms 199768 KB Output is correct
51 Correct 22 ms 199772 KB Output is correct
52 Correct 21 ms 199772 KB Output is correct
53 Correct 20 ms 199852 KB Output is correct
54 Correct 21 ms 199780 KB Output is correct
55 Correct 21 ms 199888 KB Output is correct
56 Correct 21 ms 199900 KB Output is correct
57 Correct 21 ms 199776 KB Output is correct
58 Correct 22 ms 199880 KB Output is correct
59 Correct 21 ms 199776 KB Output is correct
60 Correct 22 ms 199828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 511 ms 989652 KB Output is correct
2 Correct 498 ms 989652 KB Output is correct
3 Correct 494 ms 989780 KB Output is correct
4 Correct 518 ms 989524 KB Output is correct
5 Correct 520 ms 989712 KB Output is correct
6 Correct 492 ms 989728 KB Output is correct
7 Correct 522 ms 989576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 8536 KB Output is correct
5 Correct 254 ms 989524 KB Output is correct
6 Correct 253 ms 989780 KB Output is correct
7 Correct 269 ms 989524 KB Output is correct
8 Correct 272 ms 989688 KB Output is correct
9 Correct 251 ms 989516 KB Output is correct
10 Correct 253 ms 989468 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 257 ms 989488 KB Output is correct
13 Correct 273 ms 989712 KB Output is correct
14 Correct 254 ms 989524 KB Output is correct
15 Correct 333 ms 989708 KB Output is correct
16 Correct 314 ms 989520 KB Output is correct
17 Correct 254 ms 989776 KB Output is correct
18 Correct 504 ms 989520 KB Output is correct
19 Correct 353 ms 989804 KB Output is correct
20 Correct 260 ms 989712 KB Output is correct
21 Correct 2 ms 14680 KB Output is correct
22 Correct 2 ms 14680 KB Output is correct
23 Correct 2 ms 14684 KB Output is correct
24 Correct 2 ms 14684 KB Output is correct
25 Correct 2 ms 14684 KB Output is correct
26 Correct 2 ms 14684 KB Output is correct
27 Correct 2 ms 14684 KB Output is correct
28 Correct 2 ms 14684 KB Output is correct
29 Correct 2 ms 14684 KB Output is correct
30 Correct 2 ms 14684 KB Output is correct
31 Correct 2 ms 14684 KB Output is correct
32 Correct 2 ms 14684 KB Output is correct
33 Correct 2 ms 14684 KB Output is correct
34 Correct 1 ms 10588 KB Output is correct
35 Correct 2 ms 14876 KB Output is correct
36 Correct 5 ms 41560 KB Output is correct
37 Correct 5 ms 41564 KB Output is correct
38 Correct 4 ms 41564 KB Output is correct
39 Correct 4 ms 41564 KB Output is correct
40 Correct 5 ms 41564 KB Output is correct
41 Correct 4 ms 41564 KB Output is correct
42 Correct 4 ms 41608 KB Output is correct
43 Correct 4 ms 41564 KB Output is correct
44 Correct 5 ms 41564 KB Output is correct
45 Correct 4 ms 41564 KB Output is correct
46 Correct 5 ms 41564 KB Output is correct
47 Correct 5 ms 41564 KB Output is correct
48 Correct 5 ms 41564 KB Output is correct
49 Correct 5 ms 41564 KB Output is correct
50 Correct 5 ms 41564 KB Output is correct
51 Correct 4 ms 41568 KB Output is correct
52 Correct 5 ms 41568 KB Output is correct
53 Correct 5 ms 41568 KB Output is correct
54 Correct 5 ms 41620 KB Output is correct
55 Correct 5 ms 41428 KB Output is correct
56 Correct 5 ms 41568 KB Output is correct
57 Correct 5 ms 41564 KB Output is correct
58 Correct 5 ms 41560 KB Output is correct
59 Correct 5 ms 41816 KB Output is correct
60 Correct 4 ms 41424 KB Output is correct
61 Correct 21 ms 199768 KB Output is correct
62 Correct 21 ms 199776 KB Output is correct
63 Correct 20 ms 199776 KB Output is correct
64 Correct 21 ms 199636 KB Output is correct
65 Correct 21 ms 199660 KB Output is correct
66 Correct 21 ms 199776 KB Output is correct
67 Correct 21 ms 199776 KB Output is correct
68 Correct 23 ms 199760 KB Output is correct
69 Correct 24 ms 200032 KB Output is correct
70 Correct 21 ms 199768 KB Output is correct
71 Correct 22 ms 199772 KB Output is correct
72 Correct 21 ms 199772 KB Output is correct
73 Correct 20 ms 199852 KB Output is correct
74 Correct 21 ms 199780 KB Output is correct
75 Correct 21 ms 199888 KB Output is correct
76 Correct 21 ms 199900 KB Output is correct
77 Correct 21 ms 199776 KB Output is correct
78 Correct 22 ms 199880 KB Output is correct
79 Correct 21 ms 199776 KB Output is correct
80 Correct 22 ms 199828 KB Output is correct
81 Correct 511 ms 989652 KB Output is correct
82 Correct 498 ms 989652 KB Output is correct
83 Correct 494 ms 989780 KB Output is correct
84 Correct 518 ms 989524 KB Output is correct
85 Correct 520 ms 989712 KB Output is correct
86 Correct 492 ms 989728 KB Output is correct
87 Correct 522 ms 989576 KB Output is correct
88 Correct 269 ms 989896 KB Output is correct
89 Correct 263 ms 989524 KB Output is correct
90 Correct 248 ms 989628 KB Output is correct
91 Correct 251 ms 989652 KB Output is correct
92 Correct 269 ms 989484 KB Output is correct
93 Correct 283 ms 989776 KB Output is correct
94 Correct 350 ms 989716 KB Output is correct
95 Correct 345 ms 989732 KB Output is correct
96 Correct 438 ms 989520 KB Output is correct
97 Correct 435 ms 989480 KB Output is correct
98 Correct 316 ms 989524 KB Output is correct
99 Correct 319 ms 989748 KB Output is correct
100 Correct 318 ms 989524 KB Output is correct
101 Correct 346 ms 989844 KB Output is correct
102 Correct 315 ms 989524 KB Output is correct
103 Correct 314 ms 989716 KB Output is correct
104 Correct 334 ms 989520 KB Output is correct
105 Correct 317 ms 989524 KB Output is correct