답안 #881784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
881784 2023-12-01T22:34:14 Z AlphaMale06 Snowball (JOI21_ho_t2) C++14
100 / 100
104 ms 20640 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int a[n], b[q];
    for(int i=0; i< n; i++)cin >> a[i];
    for(int i=0; i< q; i++)cin >> b[i];
    vector<pair<int, int>> lr;
    vector<pair<int, int>> del;
    lr.pb({0, 0});
    del.pb({0, 0});
    int sum=0;
    for(int i=0; i< q; i++){
        sum+=b[i];
        pair<int, int> nxt;
        if(sum < 0){
            nxt.F=max(-sum, lr[i].F);
            nxt.S=lr[i].S;
        }
        else{
            nxt.F=lr[i].F;
            nxt.S=max(sum, lr[i].S);
        }
        lr.pb(nxt);
        del.pb({nxt.F+nxt.S, i+1});
    }
    int ans[n][2];
    for(int i=1; i< n; i++){
        int dlt=a[i]-a[i-1];
        auto itr=upper_bound(del.begin(), del.end(), mp(dlt, -1ll));
        if(itr==del.end()){
            ans[i][0]=lr[q].F;
            ans[i-1][1]=lr[q].S;
        }
        else{
            itr--;
            int ind = (*itr).S;
            ans[i][0]=min(dlt, lr[ind].F);
            ans[i-1][1]=min(dlt, lr[ind].S);
            if(lr[ind+1].F>lr[ind].F){
                ans[i][0]=dlt-ans[i-1][1];
            }
            else{
                ans[i-1][1]=dlt-ans[i][0];
            }
        }
    }
    ans[0][0]=lr[q].F;
    ans[n-1][1]=lr[q].S;
    for(int i=0; i< n; i++){
        cout << ans[i][0]+ans[i][1] << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 27 ms 12988 KB Output is correct
21 Correct 25 ms 13244 KB Output is correct
22 Correct 24 ms 12564 KB Output is correct
23 Correct 25 ms 11708 KB Output is correct
24 Correct 27 ms 12060 KB Output is correct
25 Correct 104 ms 18756 KB Output is correct
26 Correct 90 ms 18340 KB Output is correct
27 Correct 79 ms 18056 KB Output is correct
28 Correct 82 ms 18844 KB Output is correct
29 Correct 87 ms 17576 KB Output is correct
30 Correct 75 ms 17048 KB Output is correct
31 Correct 52 ms 17184 KB Output is correct
32 Correct 51 ms 16688 KB Output is correct
33 Correct 8 ms 2512 KB Output is correct
34 Correct 89 ms 18620 KB Output is correct
35 Correct 95 ms 18720 KB Output is correct
36 Correct 81 ms 19204 KB Output is correct
37 Correct 79 ms 18232 KB Output is correct
38 Correct 78 ms 18340 KB Output is correct
39 Correct 87 ms 18608 KB Output is correct
40 Correct 61 ms 18092 KB Output is correct
41 Correct 26 ms 13488 KB Output is correct
42 Correct 48 ms 16656 KB Output is correct
43 Correct 57 ms 20424 KB Output is correct
44 Correct 28 ms 13496 KB Output is correct
45 Correct 53 ms 18608 KB Output is correct
46 Correct 62 ms 20144 KB Output is correct
47 Correct 62 ms 20552 KB Output is correct
48 Correct 65 ms 20640 KB Output is correct