Submission #914896

#TimeUsernameProblemLanguageResultExecution timeMemory
914896andrei_iorgulescuLet's Win the Election (JOI22_ho_t3)C++14
10 / 100
842 ms2800 KiB
#include <bits/stdc++.h> using namespace std; using ld = long double; #define int long long int n,k; ld m; ld a[505],b[505]; ld v[505]; int better(int x,int y,ld t) { ld p1 = v[y] + b[x] / t,p2 = v[x] + b[y] / t; //cout << x << ' ' << y << ' ' << t << ' ' << p1 << ' ' << p2 << endl; if (p1 < p2) return x; //cout << y << endl; return y; } ld solve(int pos,vector<int>ids) { if (pos == m + 1) { vector<ld>as; for (auto it : ids) as.push_back(v[it]); sort(as.begin(),as.end()); ld adg = 0; for (int i = 0; i < k - m + 1; i++) adg += as[i]; return adg; } int opt = 0; for (int i = 1; i < ids.size(); i++) { int bt = better(ids[i],ids[opt],pos - 1); if (bt == ids[i]) opt = i; } //cout << opt << ' ' << ids[opt] << endl; ld pz = pos - 1; ld adg = b[ids[opt]] / pz; vector<int>newids; for (int i = 0; i < opt; i++) newids.push_back(ids[i]); for (int i = opt + 1; i < ids.size(); i++) newids.push_back(ids[i]); return adg + solve(pos + 1,newids); } signed main() { cin >> n >> k; for (int i = 1; i <= n; i++) cin >> a[i] >> b[i]; for (int i = 1; i <= n; i++) if (b[i] == -1) b[i] = 1e9; ld ans = 1e9; for (m = 1; m <= k; m++) { ///m oameni workpower, apoi doar merg prin orase for (int i = 1; i <= n; i++) v[i] = a[i] / m; vector<int>ids; for (int i = 1; i <= n; i++) ids.push_back(i); ld cur = solve(2,ids); //cout << cur << endl; ans = min(ans,cur); } cout << setprecision(5) << fixed; cout << ans; return 0; }

Compilation message (stderr)

Main.cpp: In function 'ld solve(long long int, std::vector<long long int>)':
Main.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int i = 1; i < ids.size(); i++)
      |                     ~~^~~~~~~~~~~~
Main.cpp:49:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for (int i = opt + 1; i < ids.size(); i++)
      |                           ~~^~~~~~~~~~~~
#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...