Submission #700497

#TimeUsernameProblemLanguageResultExecution timeMemory
700497PenguinsAreCuteLet's Win the Election (JOI22_ho_t3)C++17
100 / 100
488 ms2276 KiB
#include <bits/stdc++.h> using namespace std; #define INFTY 1000000069 bool comp(pair<int,int> a, pair<int,int> b) { if(a.first == -1) return false; if(b.first == -1) return true; return a < b; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int N, K; cin >> N >> K; int A[N], B[N]; pair<int, int> data[N]; for(int i = 0; i < N; i++) {cin >> data[i].second >> data[i].first;} sort(data, data + N, comp); for(int i = 0; i < N; i++) { A[i] = data[i].second; B[i] = data[i].first; } float mn = INFTY; float dp[N + 1][K + 1][2]; for(int i = 0; i <= N; i++) for(int j = 0; j <= K; j++) for(int k = 0; k < 2; k++) dp[i][j][k] = INFTY; for(int g = 0; g <= K; g++) { dp[0][0][0] = 0; if(g == 0) dp[0][0][1] = 0; for(int i = 1; i <= N; i++) for(int j = 0; j <= K; j++) { if(i - j >= 0 && i - j <= g) { if(i - j == g) dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][1]); if(j > 0) { dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j - 1][0] + A[i - 1] / (float)(g + 1)); } if(i - j > 0 && B[i - 1] != -1) { dp[i][j][0] = min(dp[i][j][0], dp[i - 1][j][0] + B[i - 1] / (float)(i - j)); } } if(g + j <= i) { dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][1]); if(j > 0) { dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j - 1][1] + A[i - 1] / (float)(g + 1)); } if(B[i - 1] != -1 && g + j == i) { dp[i][j][1] = min(dp[i][j][1], dp[i - 1][j][0] + B[i - 1] / (float)g); } } } mn = min(mn, dp[N][K - g][1]); for(int i = 0; i <= N; i++) for(int j = 0; j <= K; j++) { dp[i][j][0] = INFTY; dp[i][j][1] = INFTY; } } cout << mn; }
#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...