QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#621829 | #9427. Collect the Coins | Grand_Elf | WA | 7ms | 5844kb | C++17 | 1.2kb | 2024-10-08 17:21:10 | 2024-10-08 17:21:10 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int T, n, m, t[N], c[N];
bool check(int v) {
int l = 1, r = 1e9, p = c[1];
for (int i = 2; i <= n; i++) {
if (t[i] == t[i - 1]) {
if (r < c[i] || l > c[i]) {
return 0;
}
l = c[i];
r = c[i];
} else {
int d = t[i] - t[i - 1];
int la = max(l - d * v, 1), ra = min(r + d * v, (int)1e9);
int lb = max(p - d * v, 1), rb = min(p + d * v, (int)1e9);
bool ina = c[i] >= la && c[i] <= ra, inb = c[i] >= lb && c[i] <= rb;
if (!ina && !inb) {
return 0;
} else if (!ina) {
l = la, r = ra;
} else if (!inb) {
l = lb, r = rb;
} else {
l = min(la, lb), r = max(ra, rb);
}
p = c[i];
}
}
return 1;
}
void work() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> t[i] >> c[i];
}
for (int i = 1; i + 2 <= n; i++) {
if (t[i] == t[i + 2]) {
cout << "-1\n";
return;
}
}
int l = 0, r = 1e9;
while (l < r) {
int mid = l + r >> 1;
if (check(mid)) {
r = mid;
} else {
l = mid + 1;
}
}
cout << l << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> T;
while (T--) {
work();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5672kb
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 -1
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 7ms
memory: 5844kb
input:
1135 2 6 5 8 8 8 2 9 2 10 4 4 5 3 6 2 6 8 8 2 8 7 1 9 1 6 4 6 6 1 6 2 9 10 10 1 10 7 5 1 6 2 5 6 7 8 6 10 3 8 1 10 5 4 5 7 6 1 6 6 8 4 9 1 9 4 8 1 1 1 3 2 9 3 3 5 9 6 10 9 7 10 7 3 5 8 6 6 10 6 7 2 9 4 7 5 10 6 3 6 7 8 9 10 1 6 1 4 2 8 5 9 7 10 9 1 10 5 9 2 7 4 5 5 9 6 10 7 4 9 4 9 9 10 3 10 7 1 3 1...
output:
0 3 0 3 1 1000000000 6 0 3 2 2 0 1000000000 5 0 715827884 5 1 2 0 0 1000000000 1000000000 4 2 0 2 1 3 0 1000000000 2 3 2 5 3 1000000000 1 0 1000000000 1 1000000000 0 2 0 1 0 858993459 0 1000000000 1 0 1000000000 3 1000000000 4 1 1 1 0 613566757 3 0 1000000000 4 1000000000 3 0 0 1000000000 2 6 4 2 1 ...
result:
wrong answer 6th lines differ - expected: '3', found: '1000000000'