답안 #488560

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488560 2021-11-19T15:48:37 Z Lobo Snowball (JOI21_ho_t2) C++17
100 / 100
481 ms 16896 KB
#include <bits/stdc++.h>
 
using namespace std;

const long long INFll = (long long) 1e18 + 10;
const int INFii = (int) 1e9 + 10;
typedef long long ll;
typedef int ii;
typedef long double dbl;
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

#define maxn 220000

ii n, m;
ll w[maxn], ps[maxn], x[maxn], mx[maxn], mn[maxn], ans[maxn];

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

    //freopen("in.in", "r", stdin);
    //freopen("out.out", "w", stdout);

    cin >> n >> m;

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

    for(ii i = 1; i <= m; i++) {
        cin >> w[i];
        ps[i] = ps[i-1] + w[i];
        mn[i] = min(mn[i-1],ps[i]);
        mx[i] = max(mx[i-1],ps[i]);
    }

    ans[1]+= abs(mn[m]);
    ans[n]+= mx[m];

    for(ii i = 1; i < n; i++) {
        ll d = x[i+1]-x[i];
        if(mx[m] <= d+mn[m]) {
            ans[i]+= mx[m];
            ans[i+1]+= abs(mn[m]);
            continue;
        }


        ll l1 = 0;
        ll r1 = d;
        ll ans1 = 0;
        while(l1 <= r1) {
            ll mid1 = (l1+r1)/2;

            ll l2 = 0;
            ll r2 = m;
            ll ans2 = -1;
            while(l2 <= r2) {
                ll mid2 = (l2+r2)/2;
            
                if(mx[mid2] >= mid1) {
                    ans2 = mid2;
                    r2 = mid2-1;
                }
                else {
                    l2 = mid2+1;
                }
            }

            // cout << d << " " << mid1 << " " << ans2 << " " << endl;

            if(ans2 != -1 && d+mn[ans2] >= mid1) {
                ans1 = mid1;
                l1 = mid1+1;
            }
            else {
                r1 = mid1-1;
            }
        }

        // cout << " " << d << " " << ans1 << endl;

        ans[i]+= ans1;
        ans[i+1]+= d-ans1;
    }

    for(ii i = 1; i <= n; i++) {
        cout << ans[i] << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 464 KB Output is correct
6 Correct 3 ms 464 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 3 ms 464 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 4 ms 464 KB Output is correct
16 Correct 3 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 3 ms 464 KB Output is correct
5 Correct 3 ms 464 KB Output is correct
6 Correct 3 ms 464 KB Output is correct
7 Correct 3 ms 464 KB Output is correct
8 Correct 3 ms 464 KB Output is correct
9 Correct 2 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 368 KB Output is correct
12 Correct 0 ms 336 KB Output is correct
13 Correct 0 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 4 ms 464 KB Output is correct
16 Correct 3 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 0 ms 336 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 27 ms 8708 KB Output is correct
21 Correct 24 ms 8444 KB Output is correct
22 Correct 25 ms 8272 KB Output is correct
23 Correct 26 ms 8144 KB Output is correct
24 Correct 70 ms 8652 KB Output is correct
25 Correct 462 ms 15036 KB Output is correct
26 Correct 467 ms 15016 KB Output is correct
27 Correct 450 ms 14536 KB Output is correct
28 Correct 454 ms 14676 KB Output is correct
29 Correct 391 ms 14180 KB Output is correct
30 Correct 221 ms 13564 KB Output is correct
31 Correct 62 ms 13028 KB Output is correct
32 Correct 51 ms 13256 KB Output is correct
33 Correct 38 ms 1804 KB Output is correct
34 Correct 437 ms 15476 KB Output is correct
35 Correct 440 ms 14740 KB Output is correct
36 Correct 481 ms 15008 KB Output is correct
37 Correct 464 ms 14968 KB Output is correct
38 Correct 467 ms 14616 KB Output is correct
39 Correct 459 ms 14792 KB Output is correct
40 Correct 171 ms 14832 KB Output is correct
41 Correct 33 ms 9252 KB Output is correct
42 Correct 49 ms 13256 KB Output is correct
43 Correct 142 ms 16452 KB Output is correct
44 Correct 28 ms 9156 KB Output is correct
45 Correct 56 ms 14696 KB Output is correct
46 Correct 157 ms 16564 KB Output is correct
47 Correct 150 ms 16792 KB Output is correct
48 Correct 138 ms 16896 KB Output is correct