Submission #528040

#TimeUsernameProblemLanguageResultExecution timeMemory
528040amukkalirLet's Win the Election (JOI22_ho_t3)C++17
5 / 100
23 ms5196 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define prn printf #define scn scanf #define pii pair<int,int> #define fi first #define se second #define mp make_pair const int nax = 500; const int inf = 1e9; int n,k; double memo[nax+5][nax+5][nax+5]; vector<pii> a; double dp(int idx, int col, int rem) { if(rem == 0) return 0; if(idx == n) return inf; double &ret = memo[idx][col][rem]; if(ret!=0) return ret; ret = dp(idx+1, col, rem); // ga ambil if(a[idx].fi != inf) ret = min(ret, (double)a[idx].fi/col + dp(idx+1, col+1, rem-1)); else ret = min(ret, (double)a[idx].se/col + dp(idx+1,col,rem-1)); // cerr << idx << " " << col << " " << rem << " = " << ret << endl; return ret; } signed main () { scn("%d%d", &n, &k); a.assign(n,{0,0}); for(int i=0; i<n; i++) { scn("%d%d", &a[i].se, &a[i].fi); if(a[i].fi == -1) a[i].fi = inf; } sort(a.begin(), a.end()); for(int i=0; i<n; i++) { if(a[i].fi != inf) a.push_back(mp(inf, a[i].se)); else break; } n = a.size(); sort(a.begin(), a.end()); //for(int i=0; i<n; i++) cerr << a[i].fi << " " << a[i].se << endl; double ans = dp(0, 1, k); prn("%f", ans); } /* dp(i,j,k) = time minimum untuk visit k kota up to index i ddn j collaboratior dp(i,j,0) = 0 ambil b dp(i+1, j+1, k-1) + b[i] ambil a dp(i+1, j, k-1) + a[i] ga ambil dp(i+1, j+1, k) */

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scn("%d%d", &n, &k);
      |        ^
Main.cpp:38:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scn("%d%d", &a[i].se, &a[i].fi);
      |            ^
#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...