Submission #599057

# Submission time Handle Problem Language Result Execution time Memory
599057 2022-07-19T09:39:23 Z jmyszka2007 Snowball (JOI21_ho_t2) C++17
100 / 100
133 ms 12916 KB
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 2 * 1e5;
typedef long long ll;
ll s[MAXN + 10];
ll mx[MAXN + 10];
ll mn[MAXN + 10];
ll tab[MAXN + 10];
ll w[MAXN + 10];
ll res[MAXN + 10];
int bs(int l, int r, ll x) {
    while(l < r) {
        int mid = (l + r + 1) / 2;
        if((mx[mid] - mn[mid]) <= x) {
            l = mid;
        }
        else {
            r = mid - 1;
        }
    }
    return l;
}
int main() {
    int n, t;
    scanf("%d%d", &n, &t);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &tab[i]);
    }
    for(int i = 1; i <= t; i++) {
        scanf("%lld", &w[i]);
        s[i] = s[i - 1] + w[i];
        mx[i] = max(mx[i - 1], s[i]);
        mn[i] = min(mn[i - 1], s[i]);
    }
    for(int i = 1; i < n; i++) {
        ll d = tab[i + 1] - tab[i];
        int m = bs(0, t, d);
        res[i] += mx[m];
        res[i + 1] += mn[m] * -1;
        if(m == t) {
            continue;
        }
        if(w[m + 1] >= 0) {
            res[i] += (d - mx[m] + mn[m]);
        }
        else {
            res[i + 1] += (d - mx[m] + mn[m]);
        }
    }
    res[1] += mn[t] * -1;
    res[n] += mx[t];
    for(int i = 1; i <= n; i++) {
        printf("%lld ", res[i]);
    }
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:25:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |     scanf("%d%d", &n, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:27:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         scanf("%lld", &tab[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:30:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         scanf("%lld", &w[i]);
      |         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory 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 3 ms 592 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 448 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 448 KB Output is correct
# Verdict Execution time Memory 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 3 ms 592 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 452 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 1 ms 360 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 2 ms 448 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 448 KB Output is correct
20 Correct 28 ms 7316 KB Output is correct
21 Correct 26 ms 7212 KB Output is correct
22 Correct 26 ms 7268 KB Output is correct
23 Correct 27 ms 7360 KB Output is correct
24 Correct 38 ms 7764 KB Output is correct
25 Correct 105 ms 12012 KB Output is correct
26 Correct 100 ms 11936 KB Output is correct
27 Correct 101 ms 11832 KB Output is correct
28 Correct 105 ms 11916 KB Output is correct
29 Correct 108 ms 11616 KB Output is correct
30 Correct 93 ms 11252 KB Output is correct
31 Correct 67 ms 10800 KB Output is correct
32 Correct 57 ms 10772 KB Output is correct
33 Correct 11 ms 1876 KB Output is correct
34 Correct 133 ms 12732 KB Output is correct
35 Correct 102 ms 12492 KB Output is correct
36 Correct 103 ms 12128 KB Output is correct
37 Correct 109 ms 12576 KB Output is correct
38 Correct 97 ms 12532 KB Output is correct
39 Correct 100 ms 12624 KB Output is correct
40 Correct 78 ms 12560 KB Output is correct
41 Correct 30 ms 8008 KB Output is correct
42 Correct 57 ms 11596 KB Output is correct
43 Correct 75 ms 12736 KB Output is correct
44 Correct 32 ms 8000 KB Output is correct
45 Correct 64 ms 12600 KB Output is correct
46 Correct 82 ms 12812 KB Output is correct
47 Correct 87 ms 12916 KB Output is correct
48 Correct 79 ms 12036 KB Output is correct