QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#727358 | #5978. Runaway Quail | SunsetGlow95 | 23 ✓ | 8ms | 7788kb | C++14 | 3.6kb | 2024-11-09 12:56:34 | 2024-11-09 12:56:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MXN = 505;
const double INF = 1e18;
int T, C, N, aid, bid;
int pos[MXN], spd[MXN], aps[MXN], bps[MXN];
double mnt[MXN][MXN][2], ans;
inline double gettime(double cur, double p, int tgt) {
//cout << "gettime " << cur << ' ' << p << ' ' << tgt << ' ';
int v(pos[tgt] > 0 ? C : -C);
//cout << (pos[tgt] - p + cur * 1.0 * s) / (s - spd[tgt]) << endl;
return (p - pos[tgt] - cur * v) / (spd[tgt] - v);
}
inline double getpos(int id, double t) {
return pos[id] + t * spd[id];
}
inline pair<double, double> getlst(double cur, double p, int id) {
int v(pos[id] < 0 ? C : -C);
double tim = (p - pos[id] - cur * v) / (spd[id] - v);
return make_pair(tim, getpos(id, tim));
}
int main() {
scanf("%d", &T);
for (int caseid(1); caseid <= T; ++caseid) {
scanf("%d%d", &C, &N), aid = bid = 0;
for (int i(0); i != N; ++i) {
scanf("%d", &pos[i]);
if (pos[i] > 0) aps[aid++] = i;
else bps[bid++] = i;
}
for (int i(0); i != N; ++i) {
scanf("%d", &spd[i]);
if (pos[i] < 0) spd[i] = -spd[i];
}
sort(aps, aps + aid, [](int x, int y) { return spd[x] > spd[y]; });
sort(bps, bps + bid, [](int x, int y) { return spd[x] < spd[y]; });
for (int i(0); i <= aid; ++i)
for (int j(0); j <= bid; ++j) mnt[i][j][0] = mnt[i][j][1] = INF;
ans = INF;
mnt[0][0][0] = mnt[0][0][1] = 0;
for (int i(0); i <= aid; ++i) {
for (int j(0); j <= bid; ++j) {
// cout << i << ' ' << j << " 0: " << mnt[i][j][0] << endl;
// cout << i << ' ' << j << " 1: " << mnt[i][j][1] << endl;
if (mnt[i][j][0] != INF) {
// cout << i << ' ' << j << " 0:" << mnt[i][j][0] << endl;
double curpos(i ? getpos(aps[i - 1], mnt[i][j][0]) : 0);
bool lok(true), rok(true);
for (int k(i); k != aid; ++k) {
if (getpos(aps[k], mnt[i][j][0]) <= curpos) continue;
mnt[k + 1][j][0] = min(mnt[k + 1][j][0],
gettime(mnt[i][j][0], curpos, aps[k]));
lok = false;
break;
}
pair<double, double> lst(j ? getlst(mnt[i][j][0], curpos, bps[j - 1]) :
make_pair(0.0, 0.0));
for (int k(j); k != bid; ++k) {
if (getpos(bps[k], lst.first) >= lst.second) continue;
mnt[i][k + 1][1] = min(mnt[i][k + 1][1],
gettime(mnt[i][j][0], curpos, bps[k]));
rok = false;
break;
}
if (lok && rok) ans = min(ans, mnt[i][j][0]);
}
if (mnt[i][j][1] != INF) {
// cout << i << ' ' << j << " 1:" << mnt[i][j][1] << endl;
double curpos = (j ? getpos(bps[j - 1], mnt[i][j][1]) : 0);
bool lok = true, rok = true;
for (int k(j); k != bid; ++k) {
if (getpos(bps[k], mnt[i][j][1]) >= curpos) continue;
mnt[i][k + 1][1] = min(mnt[i][k + 1][1],
gettime(mnt[i][j][1], curpos, bps[k]));
rok = false;
break;
}
pair<double, double> lst(i ? getlst(mnt[i][j][1], curpos, aps[i - 1]) :
make_pair(0.0, 0.0));
for (int k(i); k != aid; ++k) {
if (getpos(aps[k], lst.first) <= lst.second) continue;
mnt[k + 1][j][0] = min(mnt[k + 1][j][0],
gettime(mnt[i][j][1], curpos, aps[k]));
lok = false;
break;
}
if (lok && rok) ans = min(ans, mnt[i][j][1]);
}
}
}
printf("Case #%d: %.9lf\n", caseid, ans);
}
return 0;
}
详细
Subtask #1:
score: 8
Accepted
Test #1:
score: 8
Accepted
time: 1ms
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.000000000 Case #2: 5.000000000 Case #3: 51133.937500000 Case #4: 429262.396142110 Case #5: 129368.012279597 Case #6: 7801.832031250 Case #7: 66656.812500000 Case #8: 607220.690423515 Case #9: 5725896.876344087 Case #10: 129205.285220126 Case #11: 64298.000000000 Case #12: 610881.705159705...
result:
ok correct! (50 test cases)
Subtask #2:
score: 15
Accepted
Test #2:
score: 15
Accepted
time: 8ms
memory: 7788kb
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.000000000 Case #2: 5.000000000 Case #3: 205911250.088888913 Case #4: 36298.000000000 Case #5: 186002.250000000 Case #6: 13741948.500000000 Case #7: 109001.125000000 Case #8: 38656.812500000 Case #9: 128881.056148055 Case #10: 8069407.987096774 Case #11: 128881.056148055 Case #12: 124955.3...
result:
ok correct! (50 test cases)
Extra Test:
score: 0
Extra Test Passed