Submission #806383

#TimeUsernameProblemLanguageResultExecution timeMemory
806383vjudge1Let's Win the Election (JOI22_ho_t3)C++17
28 / 100
2564 ms340 KiB
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

int use[555], T, n, k;
vector < pair < int, int > > AB, A, B;

ld recur(int pos, int x, int y) { 
    if(x == y) {
        ld tmp = .0;
        for(int i = 0, j = k - x; i < n && j; ++ i) {
            if(!use[i]) {
                -- j;
                tmp += (ld)A[i].first / (ld)(x + 1);
            }
        }
   //   cout << pos << ' ' << x << ' ' << y << ' ' << tmp << '\n';
        return tmp;
    }
    ld tmp = 1e6;
    ++ y;
    for(int i = pos; i < (int)B.size() - x + y; ++ i) {
        use[B[i].second] = true;
        tmp = min(tmp, (ld)B[i].first / (ld)y + recur(i + 1, x, y));
        use[B[i].second] = false;
    }
  //cout << pos << ' ' << x << ' ' << y << ' ' << tmp << '\n';
    return tmp;
}

main() {
#ifdef Home
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // Home
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    cin >> n >> k;
    AB.resize(n);
    A.resize(n);
    for(int i = 0; i < n; ++ i) {
        cin >> AB[i].first >> AB[i].second;
        A[i] = {AB[i].first, i};
    }
    sort(A.begin(), A.end());
    for(int i = 0; i < n; ++ i) {
        if(AB[A[i].second].second != -1) {
            B.push_back({AB[A[i].second].second, i});
        }
    }
    sort(B.begin(), B.end());
    ld ans = 1e6, tmp, c;
    for(int t = 0; t <= (int)B.size(); ++ t) {
        if(t == k) {
            break;
        }
   //   cout << t << " <<<<<<<<<<<<<<\n";
        ans = min(ans, recur(0, t, 0));
    //  cout << "<<<<<<<<<<<<<<<<\n\n\n\n\n";
    }
    cout << fixed << setprecision(15) << ans;
} 

Compilation message (stderr)

Main.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main() {
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:60:19: warning: unused variable 'tmp' [-Wunused-variable]
   60 |     ld ans = 1e6, tmp, c;
      |                   ^~~
Main.cpp:60:24: warning: unused variable 'c' [-Wunused-variable]
   60 |     ld ans = 1e6, tmp, c;
      |                        ^
#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...