QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#733100 | #5978. Runaway Quail | XSC062 | 0 | 0ms | 0kb | C++14 | 2.3kb | 2024-11-10 17:12:20 | 2024-11-10 17:12:24 |
answer
#include <bits/stdc++.h>
const long double eps = 1e-12;
int main() {
#ifdef ONLINE_JUDGE
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr), std::cout.tie(nullptr);
std::freopen("tiii.in", "r", stdin);
std::freopen("tiii.out", "w", stdout);
#else
std::freopen(".in", "r", stdin);
std::freopen(".out", "w", stdout);
#endif
int T;
for (std::cin >> T; T--; ) {
int v, n;
std::cin >> v >> n;
std::vector<std::pair<int, int> > a(n + 1);
for (int i = 1; i <= n; ++i)
std::cin >> a[i].first;
for (int i = 1; i <= n; ++i)
std::cin >> a[i].second;
a.emplace_back(0, 0), ++n;
std::sort(a.begin() + 1, a.end());
int p = std::lower_bound(a.begin() + 1, a.end(), std::make_pair(0, 0)) - a.begin();
std::sort(a.begin() + 1, a.begin() + p, [](std::pair<int, int> x, std::pair<int, int> y) { return x.second == y.second ? x.first < y.first : x.second > y.second; });
std::sort(a.begin() + p + 1, a.end(), [](std::pair<int, int> x, std::pair<int, int> y) { return x.second == y.second ? x.first < y.first : x.second < y.second; });
std::vector<std::vector<long double> > f(n + 1, std::vector<long double> (n + 1, 1e18));
f[1][n] = 0.;
auto at = [&](int i, long double t) {
return std::fabs(a[i].first + t * a[i].second * (i < p ? -1 : 1));
};
auto calc = [&](int i, long double t) {
return at(i, t) / (v - a[i].second);
};
// for (int i = 1; i <= n; ++i)
// printf("%d: (%d, %d)\n", i, a[i].first, a[i].second);
for (int i = 1; i <= p; ++i)
for (int j = n; j >= p; --j) {
if (i == p && j == p)
break;
long double d = 0.;
// printf("[%d, %d]: %lf\n", i, j, f[i][j]);
for (int k = i; k < p; ++k) {
if (at(k, f[i][j]) >= at(i, f[i][j]) - eps)
d = std::max(d, calc(k, f[i][j]));
// printf(" k1 = %d, d = %lf\n", k, d);
f[k + 1][j] = std::min(f[k + 1][j], f[i][j] + d + (k != j - 1) * d);
}
d = 0.;
for (int k = j; k > p; --k) {
if (at(k, f[i][j]) >= at(j, f[i][j]) - eps)
d = std::max(d, calc(k, f[i][j]));
// printf(" k2 = %d, d = %lf\n", k, d);
f[i][k - 1] = std::min(f[i][k - 1], f[i][j] + d + (k != i + 1) * d);
}
}
{
static int casetot = 0;
std::cout << "Case #" << ++casetot << ": ";
}
std::cout << std::fixed << std::setprecision(9) << f[p][p] << '\n';
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
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:
result:
Subtask #2:
score: 0
Dangerous Syscalls
Test #2:
score: 0
Dangerous Syscalls
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...