QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#728117 | #5978. Runaway Quail | Larrix | 23 ✓ | 6ms | 4044kb | C++14 | 2.9kb | 2024-11-09 14:36:09 | 2024-11-09 14:36:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int C, n, a[505], b[505];
double rs;
bool vis[505];
bool check(double p, double t) {
if (t >= rs) return 0;
double t1(0), t2(0);
for (int i = 1; i <= n; i++) if (!vis[i]) {
if (a[i] > 0) t1 = max(t1, (a[i] + b[i] * t - p) / (C - b[i]));
else t2 = max(t2, (p - a[i] + b[i] * t) / (C - b[i]));
}
double t3(0), t4(0);
for (int i = 1; i <= n; i++) if (!vis[i]) {
if (a[i] < 0) t3 = max(t3, (p + t1 * C - a[i] + b[i] * (t + t1)) / (C - b[i]));
else t4 = max(t4, (a[i] + b[i] * (t + t2) - p + t2 * C) / (C - b[i]));
}
rs = min(rs, t + min(t1 + t3, t2 + t4));
return t + max(t1, t2) >= rs;
}
bool end() {
for (int i = 1; i <= n; i++) if (!vis[i]) return 0;
return 1;
}
void dfs(double p, double t) {
if (clock() * 1.0 / CLOCKS_PER_SEC > 1.6) return;
if (check(p, t)) return;
if (end()) return rs = t, void();
int mx1(0), mx2(0), id1(0), id2(0);
for (int i = 1; i <= n; i++) if (!vis[i]) {
if (a[i] > 0) {
if (b[i] > mx1) mx1 = b[i], id1 = i;
} else {
if (b[i] > mx2) mx2 = b[i], id2 = i;
}
}
if (id1) {
double tt = (a[id1] + b[id1] * 1.0 * t - p) / (C - b[id1]);
vector<int> dl;
for (int i = 1; i <= n; i++) if (!vis[i] && a[i] > 0) {
if ((a[i] + b[i] * 1.0 * t - p) / (C - b[i]) <= tt) dl.push_back(i), vis[i] = 1;
}
dfs(p + tt * C, t + tt);
for (int i : dl) vis[i] = 0;
}
if (id2) {
double tt = (-a[id2] + b[id2] * 1.0 * t + p) / (C - b[id2]);
vector<int> dl;
for (int i = 1; i <= n; i++) if (!vis[i] && a[i] < 0) {
if ((-a[i] + b[i] * 1.0 * t + p) / (C - b[i]) <= tt) dl.push_back(i), vis[i] = 1;
}
dfs(p - tt * C, t + tt);
for (int i : dl) vis[i] = 0;
}
}
int TT;
void solve() {
cin >> C >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
rs = 1e18;
double t1(0), t2(0);
for (int i = 1; i <= n; i++) if (a[i] > 0) t1 = max(t1, a[i] * 1.0 / (C - b[i]));
for (int i = 1; i <= n; i++) if (a[i] < 0) t2 = max(t2, (b[i] * t1 + C * t1 - a[i]) / (C - b[i]));
rs = t1 + t2;
t1 = t2 = 0;
for (int i = 1; i <= n; i++) if (a[i] < 0) t1 = max(t1, a[i] * -1.0 / (C - b[i]));
for (int i = 1; i <= n; i++) if (a[i] > 0) t2 = max(t2, (b[i] * t1 + C * t1 + a[i]) / (C - b[i]));
rs = min(rs, t1 + t2);
dfs(0, 0);
cout << "Case #" << ++TT << ": " << fixed << setprecision(7) << rs << '\n';
}
signed main() {
#ifdef LARRIX
freopen("sample.in", "r", stdin);
freopen("sample.out", "w", stdout);
#endif
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T; cin >> T;
while (T--) solve();
return 0;
}
/*
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 0ms
memory: 4044kb
input:
50 4 3 -3 -6 -9 3 2 1 2 2 1 -1 1 1 1000 25 769234 -5735820 -524288 -5403090 -6429140 1574982 1 -9733628 -1407481 4093041 4117720 -3193501 -9765195 -3069520 1122216 -5799108 131072 -8482066 -256 -8021159 -8958386 -7027036 5370579 -3602534 -6834567 425 102 744 155 339 19 999 19 159 198 51 304 369 601 ...
output:
Case #1: 3.0000000 Case #2: 5.0000000 Case #3: 51133.9375000 Case #4: 429262.3961421 Case #5: 129368.0122796 Case #6: 7801.8320312 Case #7: 66656.8125000 Case #8: 607220.6904235 Case #9: 5725896.8763441 Case #10: 129205.2852201 Case #11: 64298.0000000 Case #12: 610881.7051597 Case #13: 17621.6562500...
result:
ok correct! (50 test cases)
Subtask #2:
score: 15
Accepted
Test #2:
score: 15
Accepted
time: 6ms
memory: 3832kb
input:
50 4 3 -3 -6 -9 3 2 1 2 2 1 -1 1 1 1000 500 -9650379 9806301 -6495789 -1283284 5022779 4725553 9364178 -8123302 -9609729 7847458 -142364 6983908 8147008 -3186924 7339254 -8737645 8757174 7887319 3609962 5780915 -1752801 -1657946 -9511339 5113995 -7887160 -6093170 260267 -3837106 -356098 6676924 6210...
output:
Case #1: 3.0000000 Case #2: 5.0000000 Case #3: 205911250.0888889 Case #4: 36298.0000000 Case #5: 186002.2500000 Case #6: 13741948.5000000 Case #7: 109001.1250000 Case #8: 38656.8125000 Case #9: 128881.0561481 Case #10: 8069407.9870968 Case #11: 128881.0561481 Case #12: 124955.3750000 Case #13: 12871...
result:
ok correct! (50 test cases)
Extra Test:
score: 0
Extra Test Passed