답안 #541314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541314 2022-03-23T02:47:23 Z NyanCatTW1 Snowball (JOI21_ho_t2) C++17
100 / 100
88 ms 12280 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long LL;

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

    int N, Q;
    cin >> N >> Q;

    vector<pair<LL, int> > ballDists;
    LL last;
    for (int i = 0; i < N; i++) {
        LL cur;
        cin >> cur;
        if (i) {
            ballDists.push_back(make_pair(cur - last, i));
        }

        last = cur;
    }

    sort(ballDists.begin(), ballDists.end(), greater<pair<LL, int> >());

    vector<LL> winds;
    LL curPos = 0, maxPos = 0, minPos = 0;

    vector<LL> ans(N);
    for (int i = 0; i < Q; i++) {
        LL cur;
        cin >> cur;

        curPos += cur;
        LL newMaxPos = max(maxPos, curPos);
        LL newMinPos = min(minPos, curPos);

        while (ballDists.size() && ballDists.back().first <= newMaxPos - newMinPos) {
            auto gap = ballDists.back();
            ballDists.pop_back();

            ans[gap.second] -= minPos;
            ans[gap.second - 1] += maxPos;

            LL intersectArea = gap.first - (maxPos - minPos);
            if (cur > 0) ans[gap.second - 1] += intersectArea;
            else ans[gap.second] += intersectArea;
        }

        maxPos = newMaxPos;
        minPos = newMinPos;
    }

    ans[0] -= minPos;
    ans[N - 1] += maxPos;

    for (auto gap : ballDists) {
        ans[gap.second] -= minPos;
        ans[gap.second - 1] += maxPos;
    }

    for (int i = 0; i < N; i++) {
        cout << ans[i] << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 324 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 27 ms 2332 KB Output is correct
21 Correct 25 ms 2220 KB Output is correct
22 Correct 24 ms 1992 KB Output is correct
23 Correct 21 ms 1900 KB Output is correct
24 Correct 35 ms 2584 KB Output is correct
25 Correct 84 ms 10368 KB Output is correct
26 Correct 80 ms 10228 KB Output is correct
27 Correct 84 ms 9940 KB Output is correct
28 Correct 85 ms 10040 KB Output is correct
29 Correct 88 ms 9520 KB Output is correct
30 Correct 76 ms 8892 KB Output is correct
31 Correct 73 ms 8512 KB Output is correct
32 Correct 59 ms 8464 KB Output is correct
33 Correct 8 ms 1332 KB Output is correct
34 Correct 82 ms 10588 KB Output is correct
35 Correct 79 ms 10136 KB Output is correct
36 Correct 79 ms 10284 KB Output is correct
37 Correct 82 ms 10096 KB Output is correct
38 Correct 83 ms 9912 KB Output is correct
39 Correct 85 ms 10164 KB Output is correct
40 Correct 80 ms 10100 KB Output is correct
41 Correct 27 ms 2980 KB Output is correct
42 Correct 66 ms 8524 KB Output is correct
43 Correct 79 ms 11792 KB Output is correct
44 Correct 31 ms 2848 KB Output is correct
45 Correct 87 ms 10000 KB Output is correct
46 Correct 81 ms 11924 KB Output is correct
47 Correct 83 ms 12172 KB Output is correct
48 Correct 86 ms 12280 KB Output is correct