Submission #806419

#TimeUsernameProblemLanguageResultExecution timeMemory
806419vjudge1Let's Win the Election (JOI22_ho_t3)C++17
33 / 100
2571 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); bool ok = true; 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}; ok &= AB[i].second == -1 || AB[i].second == AB[i].first; } 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; } if(!ok) { ans = min(ans, recur(0, t, 0)); continue; } ++ T; tmp = .0, c = 1; for(int i = 0; i < t; ++ i) { tmp += (ld)B[i].first / c; ++ c; use[B[i].second] = T; } for(int i = 0, j = k - t; i < n && j; ++ i) { if(use[i] != T) { -- j; tmp += (ld)A[i].first / c; } } ans = min(ans, tmp); } 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() {
      | ^~~~
#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...