QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#553906#362. Sparklersmakrav0 1ms3784kbC++202.3kb2024-09-08 22:42:532024-09-08 22:42:53

Judging History

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

  • [2024-09-08 22:42:53]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3784kb
  • [2024-09-08 22:42:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back
#define ff first
#define sc second
#define int __int128

void solve() {
    ll n, k, t; cin >> n >> k >> t;
    k--;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    int L = 0, R = 1e9;
    while (R - L > 1) {
        int M = (L + R) / 2;
        vector<int> x(n);
        for (int i = 0; i < n; i++) {
            x[i] = a[i] - 2 * M * i * t;
        }
        int psl = k, psr = k;
        for (int i = k - 1; i >= 0; i--) {
            if (x[i] > x[psl]) psl = i;
        }
        for (int i = k + 1; i < n; i++) {
            if (x[i] < x[psr]) psr = i;
        }
        if (x[psl] < x[psr] || x[0] < x[n - 1]) {
            L = M;
            continue;
        }
        int curl = k, curr = k;
        bool good = true;
        while (curl != psl) {
            int mnl = x[curl], j = curl;
            for (; x[j] <= x[curl]; j--) {
                mnl = min(mnl, x[j]);
            }
            while (curr < n && x[curl] >= x[curr]) {
                if (x[curr] <= mnl) break;
                curr++;
            }
            if (x[curr] > x[curl]) {
                good = false;
                break;
            }
            curl = j;
        }
        if (!good) {
            L = M;
            continue;
        }
        curl = 0;
        curr = n - 1;
        while (curl < psl) {
            int mnl = x[curl], j = curl + 1;
            for (; x[j] < x[curl]; j++) {
                mnl = min(mnl, x[j]);
            }
            while (curr >= 0 && x[curl] >= x[curr]) {
                if (x[curr] <= mnl) break;
                curr--;
            }
            if (x[curr] > x[curl]) {
                good = false; break;
            }
            curl = j;
        }
        if (good) R = M;
        else L = M;
    }
    cout << (ll) R << '\n';
}

signed main() {
    ll tt = 1;
    #ifdef LOCAL 
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        cin >> tt;
    #else
        ios::sync_with_stdio(false); 
        cin.tie(0); cout.tie(0);
    #endif

    while (tt--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

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

output:

181102

result:

ok single line: '181102'

Test #2:

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

input:

3 2 1
0
368765
1493921

output:

373481

result:

ok single line: '373481'

Test #3:

score: 20
Accepted
time: 1ms
memory: 3588kb

input:

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

output:

168215

result:

ok single line: '168215'

Test #4:

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

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:

477159

result:

ok single line: '477159'

Test #5:

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

input:

20 19 1
0
16714
600564
1738550
2860146
3233681
3470376
3511936
4127893
5089595
5771375
5923055
6712524
7645593
7839588
7939256
8270988
8365309
8565641
8764207

output:

242986

result:

ok single line: '242986'

Test #6:

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

input:

20 19 1
0
360130
416278
565928
1137578
1907790
2582414
3700996
4219574
4315031
4708493
5703532
6750886
7008779
7292334
7354499
8425871
8951795
9692673
9903623

output:

318641

result:

ok single line: '318641'

Test #7:

score: 0
Wrong Answer
time: 0ms
memory: 3484kb

input:

20 3 1
0
497352
601758
1175884
1245741
1585758
1746236
2367513
2732420
2739779
3351827
3525038
4143423
4321819
5000239
5107430
5312137
5958753
6370846
6513352

output:

171404

result:

wrong answer 1st lines differ - expected: '173188', found: '171404'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%