Submission #1314790

#TimeUsernameProblemLanguageResultExecution timeMemory
1314790NK_Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
51 ms500 KiB
// Success consists of going from failure to failure without loss of enthusiasm #include <bits/stdc++.h> using namespace std; #define nl '\n' #define sz(x) int(x.size()) #define pb push_back #define f first #define s second #define mp make_pair using pi = pair<int, int>; template<class T> using V = vector<T>; using vi = V<int>; using vpi = V<pi>; using db = double; const int BIG = 1e8; const db INF = 1e9; const db eps = 1e-5; int main() { cin.tie(0)->sync_with_stdio(0); int N, K; cin >> N >> K; vpi A(N); for(auto& x : A) { cin >> x.s >> x.f; if (x.f == -1) x.f = BIG; } sort(begin(A), end(A)); db ans = INF; for(int x = 0; x <= K; x++) { V<db> dp(x + 1, INF), ndp(x + 1, INF); dp[0] = 0; for(int i = 0; i < N; i++) { for(int have = 0; have <= x; have++) if (dp[have] + eps < INF) { // take i as vote if (have + 1 <= x) { ndp[have + 1] = min(ndp[have + 1], dp[have] + db(A[i].s) / db(K - x + 1)); } // take i as collaborator int c = i + 1 - have; if (c <= K - x) { if (A[i].f != BIG) { ndp[have] = min(ndp[have], dp[have] + db(A[i].f) / db(c)); } } else ndp[have] = min(ndp[have], dp[have]); dp[have] = INF; } dp.swap(ndp); } if (ans < dp[x]) break; ans = dp[x]; } cout << fixed << setprecision(15); cout << ans << nl; exit(0-0); } // Breathe In, Breathe Out
#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...