Submission #528151

#TimeUsernameProblemLanguageResultExecution timeMemory
5281518e7Let's Win the Election (JOI22_ho_t3)C++17
100 / 100
305 ms4300 KiB
//Challenge: Accepted #include <bits/stdc++.h> using namespace std; #ifdef zisk void debug(){cout << endl;} template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);} template<class T> void pary(T l, T r) { while (l != r) cout << *l << " ", l++; cout << endl; } #else #define debug(...) 0 #define pary(...) 0 #endif #define ll long long #define maxn 505 #define pii pair<int, int> #define ff first #define ss second #define io ios_base::sync_with_stdio(0);cin.tie(0); pii a[maxn]; const double inf = 1e9; double dp[maxn][maxn]; ll mi[maxn][maxn]; int main() { io int n, k; cin >> n >> k; for (int i = 0;i < n;i++) { cin >> a[i].ff >> a[i].ss; if (a[i].ss == -1) a[i].ss = 1<<30; } sort(a, a + n, [&] (pii x, pii y){return (x.ss == y.ss ? x.ff > y.ff : x.ss < y.ss);}); for (int i = n - 1;i >= 0;i--) { vector<pii> b; for (int j = n-1;j >= i;j--) b.push_back(a[j]); sort(b.begin(), b.end()); for (int j = 0;j < b.size();j++) mi[i][j+1] = mi[i][j] + b[j].ff; } double ans = 1e9; ans = mi[0][k]; for (int i = 0;i <= k;i++) { for (int x = 0;x <= k;x++) { for (int y = 0;y <= k;y++) dp[x][y] = inf; } dp[0][0] = 0; for (int x = 1;x <= k;x++) { for (int y = 0;y <= k;y++) { dp[x][y] = dp[x-1][y] + (double(a[x-1].ff)/(i+1)); if (y) { dp[x][y] = min(dp[x][y], dp[x-1][y-1] + (double)a[x-1].ss/y); } } ans = min(ans, dp[x][i] + (double(mi[x][k - x])) / (i+1)); } } cout << fixed << setprecision(10) << ans << "\n"; }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int j = 0;j < b.size();j++) mi[i][j+1] = mi[i][j] + b[j].ff;
      |                  ~~^~~~~~~~~~
#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...