| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1336116 | retarde | Let's Win the Election (JOI22_ho_t3) | C++20 | 2593 ms | 8468 KiB |
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define int long long
#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef map<int, int> mii;
typedef unordered_map<int, int> umii;
const int mod = 1e9 + 7;
const int inf = INTMAX_MAX;
const bool tc = false;
int n, k;
const int mxn = 505;
pair<ld, ld> s[mxn]; int can[mxn]; vi canv;
void st(ld &x, ld y) {x = min(x, y);}
ld solve2(int x) {
vector<vector<ld>> dp(n+1, vector<ld>(n+1, 1e18));
for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) {continue;}
// j collaboraters
dp[0][0] = ((ld)s[0].se)/((ld)((ld)x+(ld)1)); if (s[0].fi != 1e18) dp[0][1] = s[0].fi;
for (int i = 1; i < n; i++) {
for (int j = 0; j < n; j++) {
// get a col here
if (s[i].fi != 1e18 && j >= 1) {
st(dp[i][j], dp[i - 1][j - 1] + (ld)s[i].fi/(ld)(j));
}
// dont get col here
st(dp[i][j], dp[i - 1][j] + (ld)s[i].se/(ld)(x+1)); // use cols
}
}
vector<vector<ld>> smp(n+2, vector<ld>(n+2)); set<int> itms;
for (int i = n - 1; i >= 0; i--) {
itms.insert(s[i].se);
int id = 1; int sm = 0;
for (auto &x : itms) {
sm += x;
smp[i][id] = sm;
id++;
}
}
// include for 0
ld ans = 1e18;
for (int i = 0; i < n; i++) {
ld c1 = dp[i][x]; // x colls
ld c2 = 0; if (k > (i + 1)) c2 = (ld)(smp[i + 1][k-(i+1)])/(ld)(x+1);
if ((i+1) - x == k) ans = min(ans, c1);
else ans = min(ans, c1 + c2);
}
return ans;
}
inline void solve() {
cin >> n >> k;
fill(s, s + mxn, mp(1e18, 1e18)); vi ass;
for (int i = 0; i < n; i++) {
cin >> s[i].se >> s[i].fi;
ass.pb(s[i].se);
if (s[i].fi != -1) {canv.pb(i); can[i]=1;}
else s[i].fi = 1e18;
}
sort(s, s + mxn);
sort(all(ass));
ld ans = 1e18;
ld sm = 0; for (int i = 0; i < k; i++) sm += ass[i];
ans = min(ans, sm);
for (int c = 1; c <= canv.size(); c++) {
// how many contributor
ans = min(ans, solve2(c));
}
std::cout << std::fixed << std::setprecision(8) << ans << '\n';
}
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main() {
ios::sync_with_stdio(false);
cout.tie(0);
cin.tie(0);
//setIO();
int t = 1;
if (tc) {
cin >> t;
}
while (t--) {
solve();
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
