Submission #932648

# Submission time Handle Problem Language Result Execution time Memory
932648 2024-02-24T01:50:55 Z atom Money (IZhO17_money) C++17
100 / 100
837 ms 62136 KB
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;

#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif

signed main() {
    cin.tie(0) -> sync_with_stdio(0);

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

    vector <int> dp(n + 5, 1e9);
    set <int> S; // Maintaining outer-most segment
    S.insert(0); S.insert(1e9);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        // Make a new segment. Any segment should be non-decreasing.
        dp[i] = min(dp[i], dp[i - 1] + 1);
        // Continue current segment
        // The outer-most segment is [l, r], any segment (i..j) is valid if l <= a(i) <= r.
        int l = *(--S.upper_bound(a[i]));
        int r = *(S.upper_bound(a[i]));
        int j = i + 1;
        while (j <= n && l <= a[j] && a[j] <= r && a[j - 1] <= a[j]) ++j;

        debug(j, dp[i], l, r);
        for (int k = i; k < j; ++k) dp[k] = min(dp[k], dp[i - 1] + 1);
        S.insert(a[i]);
    }
    cout << dp[n] << "\n";
}


Compilation message

money.cpp: In function 'int main()':
money.cpp:9:20: warning: statement has no effect [-Wunused-value]
    9 | #define debug(...) 166
      |                    ^~~
money.cpp:34:9: note: in expansion of macro 'debug'
   34 |         debug(j, dp[i], l, r);
      |         ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 380 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 380 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 352 KB Output is correct
36 Correct 0 ms 352 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 0 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 460 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 380 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 352 KB Output is correct
35 Correct 0 ms 352 KB Output is correct
36 Correct 0 ms 352 KB Output is correct
37 Correct 1 ms 352 KB Output is correct
38 Correct 0 ms 352 KB Output is correct
39 Correct 53 ms 7200 KB Output is correct
40 Correct 86 ms 11716 KB Output is correct
41 Correct 36 ms 5988 KB Output is correct
42 Correct 37 ms 5468 KB Output is correct
43 Correct 25 ms 3936 KB Output is correct
44 Correct 96 ms 15008 KB Output is correct
45 Correct 95 ms 14928 KB Output is correct
46 Correct 98 ms 15116 KB Output is correct
47 Correct 93 ms 15128 KB Output is correct
48 Correct 89 ms 14936 KB Output is correct
49 Correct 328 ms 33364 KB Output is correct
50 Correct 324 ms 33360 KB Output is correct
51 Correct 350 ms 33560 KB Output is correct
52 Correct 320 ms 33364 KB Output is correct
53 Correct 320 ms 33584 KB Output is correct
54 Correct 324 ms 33368 KB Output is correct
55 Correct 822 ms 62096 KB Output is correct
56 Correct 814 ms 61860 KB Output is correct
57 Correct 829 ms 61936 KB Output is correct
58 Correct 800 ms 62136 KB Output is correct
59 Correct 837 ms 61732 KB Output is correct
60 Correct 834 ms 62004 KB Output is correct
61 Correct 833 ms 61880 KB Output is correct
62 Correct 834 ms 61984 KB Output is correct