Submission #507141

# Submission time Handle Problem Language Result Execution time Memory
507141 2022-01-12T09:10:24 Z dannyboy20031204 Money (IZhO17_money) C++17
100 / 100
1084 ms 55232 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
void db() {cout << endl;}
template <typename T, typename ...U> void db(T a, U ...b) {cout << a << ' ', db(b...);}
#ifdef Cloud
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define file ios::sync_with_stdio(false); cin.tie(0)
#endif
#define pii pair<int, int>
const int inf = 1e9, N = 120, _N = 501, mod = 998244353;
pair<int, int> p[_N][N]{};
pii get(pii u){
    return p[u.fi][u.se] = p[u.fi][u.se] == u ? u : get(p[u.fi][u.se]);
}
void merge(pii a, pii b){
    b = get(b);
    p[a.fi][a.se] = b;
}
int main(){
    
    file;
    /*
    int n;
    cin >> n;
    int a[n], tot = 0;
    for (int &i : a) cin >> i, tot += i;
    if (tot % 2) return cout << 0 << '\n', 0;
    int cnt[N]{};
    bool dp[N]{}, can[_N][N]{};
    for (int i = 0; i < N; i++) p[n][i] = {n, i};
    for (int i = n - 1; i >= 0; i--){
        for (int j = 0; j < N; j++) p[i][j] = p[i + 1][j];
        for (int j = a[i]; j < N; j++) merge(p[i][j], p[i + 1][j - a[i]]);
    }
    dp[0] = 1;
    //db(p[3][8]);
    for (int i = 0; i < n; i++){
        bool can[N]{};
        for (int j = 0; j < N; j++) if (dp[j]) {
            auto u = get(i + 1, j);
            can[u.fi][u.se] = 1;
        }
        for (int j = 0; j < N; j++) {
            auto u = get(i + 1, j);
            if (can[u.fi][u.se] and j * 2 >= tot - a[i]){
                db(i, j, j * 2 - tot + a[i]);
                cnt[j * 2 - tot + a[i]]++;
            }
        }
        for (int j = N - 1; j >= a[i]; j--) dp[j] |= dp[j - a[i]];
    }
    if (!dp[tot / 2]) return cout << 0 << '\n', 0;
    vector<int> ans;
    for (int i = 1; i < N; i++) if (cnt[i] == n) ans.push_back(i);
    cout << ans.size() << '\n';
    for (int i : ans) cout << i << ' ';
    */
    int n;
    cin >> n;
    int a[n], ans = 0;
    for (int &i : a) cin >> i;
    set<int> s;
    for (int i = 0; i < n; i++){
        ans++;
        auto it = s.upper_bound(a[i]);
        int x = it == s.end() ? inf : *it;
        s.insert(a[i]);
        //db(i, x);
        while (i + 1 < n and a[i + 1] >= a[i] and a[i + 1] <= x)
            i++, s.insert(a[i]);
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 328 KB Output is correct
25 Correct 0 ms 320 KB Output is correct
26 Correct 0 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 328 KB Output is correct
25 Correct 0 ms 320 KB Output is correct
26 Correct 0 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 0 ms 324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 316 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 324 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 320 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 328 KB Output is correct
25 Correct 0 ms 320 KB Output is correct
26 Correct 0 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 204 KB Output is correct
31 Correct 1 ms 320 KB Output is correct
32 Correct 1 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 1 ms 204 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 1 ms 204 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 0 ms 324 KB Output is correct
39 Correct 72 ms 5352 KB Output is correct
40 Correct 125 ms 3980 KB Output is correct
41 Correct 41 ms 2308 KB Output is correct
42 Correct 37 ms 2140 KB Output is correct
43 Correct 37 ms 1840 KB Output is correct
44 Correct 111 ms 4708 KB Output is correct
45 Correct 116 ms 4808 KB Output is correct
46 Correct 106 ms 4792 KB Output is correct
47 Correct 95 ms 4804 KB Output is correct
48 Correct 128 ms 4804 KB Output is correct
49 Correct 487 ms 23304 KB Output is correct
50 Correct 534 ms 25140 KB Output is correct
51 Correct 537 ms 26216 KB Output is correct
52 Correct 464 ms 25156 KB Output is correct
53 Correct 435 ms 25924 KB Output is correct
54 Correct 526 ms 26148 KB Output is correct
55 Correct 1067 ms 54684 KB Output is correct
56 Correct 982 ms 54864 KB Output is correct
57 Correct 1030 ms 54724 KB Output is correct
58 Correct 1018 ms 54760 KB Output is correct
59 Correct 1074 ms 51728 KB Output is correct
60 Correct 1054 ms 51684 KB Output is correct
61 Correct 1014 ms 55232 KB Output is correct
62 Correct 1084 ms 55184 KB Output is correct