QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#613677 | #9427. Collect the Coins | Null_Resot | WA | 0ms | 3552kb | C++20 | 1.7kb | 2024-10-05 14:27:30 | 2024-10-05 14:27:52 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
using u64 = unsigned long long;
typedef std::pair<long long, long long> PII;
const int mod = 998244353;
const int N = 2e6 + 1000;
const int INF = 0x3f3f3f3f;
const long long LINF = 1e18;
const double eps = 1e-12;
const double pi = std::acos(-1);
std::mt19937_64 rnd(std::random_device{}());
void solve() {
int n;
std::cin >> n;
std::vector<PII> a(n);
for (auto &[t, p] : a) std::cin >> t >> p;
auto check = [&](i64 v) {
i64 l = -INF, r = INF;
i64 pos = 0, last = 0;
for (auto [t, p] : a) {
if (!pos) {
pos = p;
last = t;
continue;
}
i64 w = (t - last) * v;
if ((pos - w <= p && p <= pos + w) && (l - w <= p && p <= r + w)) {
l = std::min(l - w, pos - w);
r = std::max(r + w, pos + w);
} else if (pos - w <= p && p <= pos + w) {
l -= w;
r += w;
} else if (l - w <= p && p <= r + w) {
l = pos - w;
r = pos + w;
} else {
return false;
}
pos = p;
last = t;
}
return true;
};
i64 l = 0, r = 1e9;
while (l < r) {
i64 mid = (l + r) >> 1;
if (check(mid)) r = mid;
else l = mid + 1;
}
if (r > 1e9) r = -1;
std::cout << r << "\n";
}
signed main() {
std::ios::sync_with_stdio(false), std::cin.tie(nullptr), std::cout.tie(nullptr);
int tmp = 1;
std::cin >> tmp;
while (tmp--)
solve();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3552kb
input:
3 5 1 1 3 7 3 4 4 3 5 10 1 10 100 3 10 100 10 1000 10 10000
output:
2 0 1000000000
result:
wrong answer 3rd lines differ - expected: '-1', found: '1000000000'