QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#613677#9427. Collect the CoinsNull_ResotWA 0ms3552kbC++201.7kb2024-10-05 14:27:302024-10-05 14:27:52

Judging History

你现在查看的是最新测评结果

  • [2024-11-06 15:56:27]
  • hack成功,自动添加数据
  • (/hack/1139)
  • [2024-10-05 14:27:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2024-10-05 14:27:30]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'