QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#110915#362. Sparklersbashkort0 2ms3412kbC++202.4kb2023-06-04 18:48:132023-06-04 18:48:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-04 18:48:17]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3412kb
  • [2023-06-04 18:48:13]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k, t;
    cin >> n >> k >> t;
    k -= 1;

    vector<ll> x(n);

    for (int i = 0; i < n; ++i) {
        cin >> x[i];
        x[i] *= 2;
    }
    t *= 2;

    auto check = [&](int s) -> bool {
        ll T = 1LL * t * s;

        ll D = 0;
        for (int i = k - 1; i >= 0; --i) {
            ll p = x[k] - x[i] - 2 * T * (k - i - 1);
            assert(p % 2 == 0);
            D = max(D, p / 2);
        }

        if (D <= T) {
            if (k == n - 1) {
                return true;
            }
            if (x[k + 1] - T <= x[k] - D + T) {
                bool ok = true;
                ll p = x[k] - D + T;
                for (int i = k + 2; i < n; ++i) {
                    ok &= p + T * (i - k - 1) >= x[i] - T * (i - k);
                }
                if (ok) {
                    return true;
                }
            }
        }

        if (k > 0) {
            ll wait = 3e18;

            for (int i = k - 1; i >= 0; --i) {
                wait = min(wait, x[i] - x[k] + 2 * T * (k - i));
            }

            if (wait >= 0) {
                ll m = (x[k - 1] + wait + x[k]) / 2;
                assert(m * 2 == x[k - 1] + wait + x[k]);
                bool ok = true;
                for (int i = k + 1; i < n; ++i) {
                    ok &= x[i] - T * (i - k + 1) <= m + T * (i - k);
                }
                if (ok) {
                    return true;
                }
            }
        }

        return false;
    };

    auto ck = [&](ll mid) {
        if (check(mid)) {
            return true;
        }

        ll X = x[n - 1];
        for (int i = 0; i < n; ++i) {
            x[i] = X - x[i];
        }
        k = n - k - 1;
        reverse(x.begin(), x.end());

        bool res = check(mid);

        X = x[n - 1];
        for (int i = 0; i < n; ++i) {
            x[i] = X - x[i];
        }
        k = n - k - 1;
        reverse(x.begin(), x.end());

        return res;
    };

    int lo = -1, hi = 2e9 / t + 1;

    while (lo + 1 < hi) {
        int mid = lo + hi >> 1;
        if (ck(mid)) {
            hi = mid;
        } else {
            lo = mid;
        }
    }

    cout << hi << '\n';

    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 0ms
memory: 3408kb

input:

10 9 2
0
1117660
2284171
3390084
3568342
4222750
5180454
6186411
6360445
6519656

output:

181102

result:

ok single line: '181102'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3404kb

input:

3 2 1
0
368765
1493921

output:

373481

result:

ok single line: '373481'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3412kb

input:

9 8 4
0
1970871
2488111
3723411
5581758
7596649
8984403
9989980
10451978

output:

168215

result:

ok single line: '168215'

Test #4:

score: -20
Wrong Answer
time: 2ms
memory: 3352kb

input:

20 18 1
0
462590
635597
1653028
1731039
2632280
2993419
3958675
4824859
4923991
5874922
6721441
7856685
8109245
8187843
8916119
9662776
10617094
11598860
11759660

output:

484021

result:

wrong answer 1st lines differ - expected: '477159', found: '484021'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%