QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733935 | #5978. Runaway Quail | londono | 23 ✓ | 3123ms | 5188kb | C++14 | 2.6kb | 2024-11-10 22:12:30 | 2024-11-10 22:12:35 |
Judging History
answer
#include <bits/stdc++.h>
#define dec double
using namespace std;
const int N = 505;
int n, n1, n2; dec c;
struct node{ int x, v; }a[N], a1[N], a2[N];
dec dp[N][N];
dec calc1(dec now, int i) { return (dec)(now*a1[i].v+abs(a1[i].x))/(c-a1[i].v); }
dec calc2(dec now, int i) { return (dec)(now*a2[i].v+abs(a2[i].x))/(c-a2[i].v); }
int main() {
// g++ code.cpp -o code.exe -std=c++14 -O2 -fno-ms-extensions "-Wl,--stack=1000000000" -DLOCAL; ./code
time_t stm = clock();
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("ans.out", "w", stdout);
#else
// freopen("tiii.in", "r", stdin);
// freopen("tiii.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#endif
int Case = 0;
int T; cin >> T; while (T--) {
n1 = n2 = 0; cin >> c >> n;
for (int i = 1; i <= n; i++) cin >> a[i].x;
for (int i = 1; i <= n; i++) cin >> a[i].v;
sort(a+1, a+n+1, [](node lhs, node rhs) -> bool {
return lhs.x < rhs.x;
});
for (int i = n; i >= 1; i--) {
if (a[i].x < 0) {
a1[++n1] = a[i];
}
}
for (int i = 1; i <= n; i++) {
if (a[i].x > 0) {
a2[++n2] = a[i];
}
}
// cout << calc1(0, 1) << '\n';
for (int i = 0; i <= n1; i++) {
for (int j = 0; j <= n2; j++) {
dp[i][j] = 1e18;
}
}
dp[0][0] = 0;
for (int k = 0; k <= n; k++) {
for (int i = 0; i <= n1; i++) {
for (int j = 0; j <= n2; j++) {
if (i+j!=k) continue;
dec wl = 0;
for (int l = i+1; l <= n1; l++) {
wl = max(wl, calc1(dp[i][j], l));
// printf("[%d,%d]->[%d,%d] %.2lf: %.2lf,%d\n", i, j, l, j, calc1(dp[i][j], l), dp[i][j], l);
dp[l][j] = min(dp[l][j], dp[i][j]+wl+wl*(j+l<n));
}
dec wr = 0;
for (int r = j+1; r <= n2; r++) {
wr = max(wr, calc2(dp[i][j], r));
// printf("[%d,%d]->[%d,%d] %.2lf\n", i, j, i, r, calc2(dp[i][j], r));
dp[i][r] = min(dp[i][r], dp[i][j]+wr+wr*(i+r<n));
}
}
}
}
cout << "Case #" << (++Case) << ": ";
cout << fixed << setprecision(10) << dp[n1][n2] << '\n';
}
cerr << "Exec Time: " << (double)(clock()-stm)/CLOCKS_PER_SEC << "s" << endl;
return 0;
}
详细
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 0ms
memory: 3996kb
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.0000000000 Case #2: 5.0000000000 Case #3: 51133.9375000000 Case #4: 429262.3961421099 Case #5: 129368.0122795970 Case #6: 7801.8320312500 Case #7: 66656.8125000000 Case #8: 607220.6904235146 Case #9: 5725896.8763440857 Case #10: 129205.2852201258 Case #11: 64298.0000000000 Case #12: 61088...
result:
ok correct! (50 test cases)
Subtask #2:
score: 15
Accepted
Test #2:
score: 15
Accepted
time: 3123ms
memory: 5188kb
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.0000000000 Case #2: 5.0000000000 Case #3: 205911250.0888889134 Case #4: 36298.0000000000 Case #5: 186002.2500000000 Case #6: 13741948.5000000000 Case #7: 109001.1250000000 Case #8: 38656.8125000000 Case #9: 128881.0561480552 Case #10: 8069407.9870967744 Case #11: 128881.0561480552 Case #1...
result:
ok correct! (50 test cases)
Extra Test:
score: 0
Extra Test Passed