답안 #879655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879655 2023-11-27T19:45:52 Z mychecksedad Let's Win the Election (JOI22_ho_t3) C++17
21 / 100
542 ms 989848 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];
   
      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 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6592 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 309 ms 989504 KB Output is correct
6 Correct 280 ms 989592 KB Output is correct
7 Correct 273 ms 989660 KB Output is correct
8 Correct 273 ms 989668 KB Output is correct
9 Correct 269 ms 989528 KB Output is correct
10 Correct 267 ms 989524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6592 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 309 ms 989504 KB Output is correct
6 Correct 280 ms 989592 KB Output is correct
7 Correct 273 ms 989660 KB Output is correct
8 Correct 273 ms 989668 KB Output is correct
9 Correct 269 ms 989528 KB Output is correct
10 Correct 267 ms 989524 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 269 ms 989704 KB Output is correct
13 Correct 272 ms 989712 KB Output is correct
14 Correct 274 ms 989624 KB Output is correct
15 Correct 339 ms 989524 KB Output is correct
16 Correct 315 ms 989716 KB Output is correct
17 Correct 268 ms 989668 KB Output is correct
18 Correct 500 ms 989776 KB Output is correct
19 Correct 384 ms 989564 KB Output is correct
20 Correct 275 ms 989848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 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 14936 KB Output is correct
9 Incorrect 2 ms 14680 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 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 14936 KB Output is correct
9 Incorrect 2 ms 14680 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14684 KB Output is correct
2 Correct 2 ms 14684 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 14936 KB Output is correct
9 Incorrect 2 ms 14680 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 523 ms 989524 KB Output is correct
2 Correct 533 ms 989748 KB Output is correct
3 Correct 528 ms 989720 KB Output is correct
4 Correct 532 ms 989520 KB Output is correct
5 Correct 542 ms 989812 KB Output is correct
6 Correct 534 ms 989488 KB Output is correct
7 Correct 536 ms 989716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 6592 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 309 ms 989504 KB Output is correct
6 Correct 280 ms 989592 KB Output is correct
7 Correct 273 ms 989660 KB Output is correct
8 Correct 273 ms 989668 KB Output is correct
9 Correct 269 ms 989528 KB Output is correct
10 Correct 267 ms 989524 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 269 ms 989704 KB Output is correct
13 Correct 272 ms 989712 KB Output is correct
14 Correct 274 ms 989624 KB Output is correct
15 Correct 339 ms 989524 KB Output is correct
16 Correct 315 ms 989716 KB Output is correct
17 Correct 268 ms 989668 KB Output is correct
18 Correct 500 ms 989776 KB Output is correct
19 Correct 384 ms 989564 KB Output is correct
20 Correct 275 ms 989848 KB Output is correct
21 Correct 2 ms 14684 KB Output is correct
22 Correct 2 ms 14684 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 14936 KB Output is correct
29 Incorrect 2 ms 14680 KB Output isn't correct
30 Halted 0 ms 0 KB -