답안 #920397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
920397 2024-02-02T14:08:10 Z borisAngelov Snowball (JOI21_ho_t2) C++17
100 / 100
81 ms 17084 KB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 200005;

int n, m;

long long a[maxn];
long long b[maxn];

long long maxDeltaL[maxn];
long long maxDeltaR[maxn];

long long maxLeft[maxn];
long long maxRight[maxn];

void fastIO()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main()
{
    fastIO();

    cin >> n >> m;

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }

    for (int i = 1; i <= m; ++i)
    {
        cin >> b[i];
    }

    long long currDelta = 0;

    for (int i = 1; i <= m; ++i)
    {
        currDelta += b[i];
        maxDeltaL[i] = min(maxDeltaL[i - 1], currDelta);
        maxDeltaR[i] = max(maxDeltaR[i - 1], currDelta);
    }

    maxLeft[1] = a[1] + maxDeltaL[m];
    maxRight[n] = a[n] + maxDeltaR[m];

    for (int i = 1; i <= n - 1; ++i)
    {
        // min time to intersect

        int l = 1;
        int r = m;

        while (l <= r)
        {
            int mid = (l + r) / 2;

            if (a[i] + maxDeltaR[mid] <= a[i + 1] + maxDeltaL[mid])
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }

        maxRight[i] = a[i] + maxDeltaR[r];
        maxLeft[i + 1] = a[i + 1] + maxDeltaL[r];

        if (l <= m)
        {
            //decides who will get the snow

            if (b[l] < 0)
            {
                maxLeft[i + 1] = maxRight[i];
            }
            else
            {
                maxRight[i] = maxLeft[i + 1];
            }
        }
    }

    for (int i = 1; i <= n; ++i)
    {
        cout << maxRight[i] - maxLeft[i] << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 1 ms 6744 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6488 KB Output is correct
4 Correct 2 ms 6492 KB Output is correct
5 Correct 2 ms 6492 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 2 ms 6488 KB Output is correct
8 Correct 2 ms 6488 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 2 ms 6744 KB Output is correct
11 Correct 1 ms 6744 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 2 ms 6488 KB Output is correct
16 Correct 2 ms 6492 KB Output is correct
17 Correct 2 ms 6488 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 19 ms 7768 KB Output is correct
21 Correct 19 ms 9564 KB Output is correct
22 Correct 18 ms 9304 KB Output is correct
23 Correct 18 ms 9296 KB Output is correct
24 Correct 22 ms 9552 KB Output is correct
25 Correct 81 ms 15544 KB Output is correct
26 Correct 77 ms 15032 KB Output is correct
27 Correct 76 ms 14640 KB Output is correct
28 Correct 80 ms 14712 KB Output is correct
29 Correct 76 ms 14172 KB Output is correct
30 Correct 75 ms 13792 KB Output is correct
31 Correct 47 ms 13140 KB Output is correct
32 Correct 46 ms 13136 KB Output is correct
33 Correct 8 ms 7512 KB Output is correct
34 Correct 80 ms 15440 KB Output is correct
35 Correct 77 ms 14672 KB Output is correct
36 Correct 78 ms 14928 KB Output is correct
37 Correct 79 ms 14828 KB Output is correct
38 Correct 77 ms 14640 KB Output is correct
39 Correct 76 ms 15128 KB Output is correct
40 Correct 53 ms 14764 KB Output is correct
41 Correct 20 ms 10320 KB Output is correct
42 Correct 43 ms 13392 KB Output is correct
43 Correct 55 ms 16788 KB Output is correct
44 Correct 20 ms 10320 KB Output is correct
45 Correct 50 ms 14676 KB Output is correct
46 Correct 54 ms 16792 KB Output is correct
47 Correct 59 ms 16896 KB Output is correct
48 Correct 56 ms 17084 KB Output is correct