답안 #854149

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
854149 2023-09-26T09:05:40 Z BrineTw Snowball (JOI21_ho_t2) C++14
100 / 100
86 ms 11388 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

#define debug(x) cerr << #x << ' ' << x << '\n'
#define endl '\n'

using namespace std;

const int M = 1e9 + 7;
typedef long long ll;


int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, Q;
    cin >> N >> Q;

    vector<ll> x(N);
    vector<ll> w(Q);
    for (auto& n: x) cin >> n;
    for (auto& n: w) cin >> n;

    vector<ll> snow(N - 1);
    for (int i = 1; i < N; i++) {
        snow[i - 1] = x[i] - x[i - 1];
    }

    vector<ll> left(Q + 1);
    vector<ll> right(Q + 1);
    
    ll cur = 0;
    for (int i = 1; i <= Q; i++) {
        cur += w[i - 1];
        left[i] = min(left[i - 1], cur);
        right[i] = max(right[i - 1], cur);
    }
    for (int i = 0; i <= Q; i++) {
        left[i] = abs(left[i]);
    }

    vector<ll> ans(N);
    for (int i = 0; i < N - 1; i++) {
        ll l = 0, m, r = Q;
        while (r - l > 1) {
            m = l + r >> 1;
            (left[m] + right[m] < snow[i] ? l : r) = m;
        }
        
        ans[i] += right[l];
        ans[i + 1] += left[l];

        if (w[l] < 0) {
            ans[i + 1] -= left[l];
            ans[i + 1] += min(left[r], snow[i] - right[r]);
        } else {
            ans[i] -= right[l];
            ans[i] += min(right[r], snow[i] - left[r]);
        }
    }

    ans[0] += left.back();
    ans.back() += right.back();

    for (auto& n: ans) cout << n << '\n';

    return 0;   
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:45:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   45 |             m = l + r >> 1;
      |                 ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 21 ms 5140 KB Output is correct
21 Correct 20 ms 4952 KB Output is correct
22 Correct 19 ms 4956 KB Output is correct
23 Correct 18 ms 5208 KB Output is correct
24 Correct 22 ms 5712 KB Output is correct
25 Correct 75 ms 11340 KB Output is correct
26 Correct 83 ms 11256 KB Output is correct
27 Correct 74 ms 11088 KB Output is correct
28 Correct 80 ms 11344 KB Output is correct
29 Correct 75 ms 11020 KB Output is correct
30 Correct 76 ms 10576 KB Output is correct
31 Correct 55 ms 10064 KB Output is correct
32 Correct 50 ms 10064 KB Output is correct
33 Correct 9 ms 1368 KB Output is correct
34 Correct 76 ms 11388 KB Output is correct
35 Correct 77 ms 11092 KB Output is correct
36 Correct 76 ms 11344 KB Output is correct
37 Correct 74 ms 11092 KB Output is correct
38 Correct 75 ms 11092 KB Output is correct
39 Correct 86 ms 11088 KB Output is correct
40 Correct 67 ms 10996 KB Output is correct
41 Correct 20 ms 4952 KB Output is correct
42 Correct 50 ms 9992 KB Output is correct
43 Correct 60 ms 11272 KB Output is correct
44 Correct 26 ms 4944 KB Output is correct
45 Correct 61 ms 11108 KB Output is correct
46 Correct 60 ms 11344 KB Output is correct
47 Correct 63 ms 11380 KB Output is correct
48 Correct 62 ms 11380 KB Output is correct