제출 #785052

#제출 시각아이디문제언어결과실행 시간메모리
785052gun_ganLet's Win the Election (JOI22_ho_t3)C++17
10 / 100
556 ms1008536 KiB
#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;
 
int main() {
      cin.tie(0); ios_base::sync_with_stdio(0);
 
      for(int i = 0; i < MX; i++)
            for(int j = 0; j < MX; j++)
                  for(int k = 0; k < MX; k++)
                        dp[i][j][k] = 1e9;
 
      cin >> N >> K;
 
      for(int i = 1; i <= N; i++) {
            cin >> a[i] >> b[i];
            v.push_back({b[i], a[i]});
      }
 
      sort(v.begin(), v.end(), [&](auto x, auto y) {
            if(x.first == -1 && y.first == -1) return x.second < y.second;
            if(x.first == -1) return false;
            if(y.first == -1) return true;

            if(x.first - x.second == y.first - y.second) return x.first < y.first;

            return x.first - x.second < y.first - y.second;
      });
 
      dp[0][0][0] = 0;
      for(int i = 0; i <= N; i++) {
            for(int j = 0; j <= N; j++) { // votes
                  for(int k = 0; k <= N; 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 / (k + 1));
                        
                        // ambil collaborator
                        if(v[i].first != -1) 
                              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));
                  }
            }
      }
 
      double ans = 1e9;
      for(int k = 0; k <= N; k++) {
            ans = min(ans, dp[N][K][k]);
      }
 
      cout << fixed << setprecision(15) << ans << '\n';
 
}   
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...