Submission #907602

#TimeUsernameProblemLanguageResultExecution timeMemory
907602vjudge1Let's Win the Election (JOI22_ho_t3)C++17
0 / 100
489 ms1048576 KiB
#pragma GCC target ("avx2") #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include<bits/stdc++.h> #include<math.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<ll, ll> pl; typedef vector<ll> vl; #define FD(i, r, l) for(ll i = r; i > (l); --i) #define K first #define V second #define G(x) ll x; cin >> x; #define GD(x) ld x; cin >> x; #define GS(s) string s; cin >> s; #define EX(x) { cout << x << '\n'; exit(0); } #define A(a) (a).begin(), (a).end() #define F(i, l, r) for (ll i = l; i < (r); ++i) #define NN 510 #define M 1000000007 // 998244353 vector<pl> votes; ll n, k; ll take; ld dp[NN][NN][NN]; // ld rec(ll i, ll bs, ll vots) { if (i == n) return vots + bs >= k and bs >= take ? 0: 1e18; auto &DP = dp[i][bs][vots]; if (DP != DP) { DP = 1e18; DP = min(DP, rec(i+1, bs, vots)); DP = min(DP, rec(i+1, bs, vots+1) + ld(votes[i].V)/(1 + take)); if (~votes[i].K) DP = min(DP, rec(i+1, bs+1, vots) + ld(votes[i].K)/(1 + bs)); } return DP; } ld cache[510]; ld q(ll i) { take = i; if (i < 0 || i > n) return 1e18; if (cache[i] == cache[i]) return cache[i]; memset(dp, -1, sizeof dp); return cache[i] = rec(0, 0, 0); } int main(){ // freopen("a.in", "r", stdin); // freopen("a.out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20); cin >> n >> k; votes.resize(n); for (auto &[b, a]: votes) { cin >> a >> b; } memset(cache, -1, sizeof cache); sort(A(votes)); ld ans = 1e18; ll l = -1, r = n; while (l+1<r) { ll mid = (l+r)/2; if (q(mid) < q(mid+1)) l = mid; else r = mid; } F(th, l-2, l+3) ans = min(ans, q(l)); cout << ans << endl; }
#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...