답안 #758011

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
758011 2023-06-14T04:43:30 Z otarius Snowball (JOI21_ho_t2) C++17
100 / 100
116 ms 13376 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
 
#define int long long
// #define int unsigned long long
 
const ll inf = 1e18 + 7;
const ll weirdMod = 998244353;
 
int rgt[200005], lft[200005];
void solve() {
    int n, k;
    cin >> n >> k;
    int arr[n + 5] = {}, wnd[k + 5] = {};
    for (int i = 1; i <= n; i++)
        cin >> arr[i];
    for (int i = 1; i <= k; i++) {
        cin >> wnd[i]; wnd[i] += wnd[i - 1];
    } vector<int> vec;
    for (int i = 1; i <= k; i++) {
        rgt[i] = max(rgt[i - 1], wnd[i]);
        lft[i] = max(lft[i - 1], -wnd[i]);
    } ll ans[n + 5] = {};
    arr[0] = -inf; arr[n + 1] = inf;
    for (int i = 0; i <= n; i++) {
        if (rgt[k] + lft[k] <= arr[i + 1] - arr[i]) {
            ans[i] += rgt[k]; ans[i + 1] += lft[k]; continue;
        } int l = 1, r = k, m;
        while (l < r) {
            m = (l + r) / 2;
            if (rgt[m] + lft[m] > arr[i + 1] - arr[i])
                r = m;
            else l = m + 1;
        } while (rgt[l - 1] + lft[l - 1] > arr[i + 1] - arr[i]) l--;
        if (lft[l] != lft[l - 1]) {
            ans[i] += rgt[l]; ans[i + 1] += arr[i + 1] - arr[i] - rgt[l];
        } else {ans[i] += arr[i + 1] - arr[i] - lft[l]; ans[i + 1] += lft[l];}
    } for (int i = 1; i <= n; i++)
        cout << ans[i] << '\n';
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
 
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        cout << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 388 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 396 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 396 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 388 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 328 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 396 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 396 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 29 ms 6708 KB Output is correct
21 Correct 29 ms 6700 KB Output is correct
22 Correct 30 ms 6732 KB Output is correct
23 Correct 25 ms 6616 KB Output is correct
24 Correct 28 ms 7124 KB Output is correct
25 Correct 98 ms 11652 KB Output is correct
26 Correct 95 ms 11588 KB Output is correct
27 Correct 100 ms 11200 KB Output is correct
28 Correct 99 ms 11316 KB Output is correct
29 Correct 93 ms 11080 KB Output is correct
30 Correct 92 ms 10688 KB Output is correct
31 Correct 65 ms 10268 KB Output is correct
32 Correct 65 ms 10228 KB Output is correct
33 Correct 9 ms 1620 KB Output is correct
34 Correct 96 ms 11960 KB Output is correct
35 Correct 116 ms 11320 KB Output is correct
36 Correct 97 ms 11592 KB Output is correct
37 Correct 96 ms 11328 KB Output is correct
38 Correct 99 ms 11196 KB Output is correct
39 Correct 95 ms 11444 KB Output is correct
40 Correct 71 ms 11316 KB Output is correct
41 Correct 41 ms 6740 KB Output is correct
42 Correct 73 ms 10292 KB Output is correct
43 Correct 77 ms 13128 KB Output is correct
44 Correct 33 ms 6724 KB Output is correct
45 Correct 65 ms 11332 KB Output is correct
46 Correct 79 ms 13376 KB Output is correct
47 Correct 88 ms 13220 KB Output is correct
48 Correct 80 ms 13200 KB Output is correct