Submission #465027

# Submission time Handle Problem Language Result Execution time Memory
465027 2021-08-14T21:13:22 Z TeaTime Money (IZhO17_money) C++17
100 / 100
1369 ms 101120 KB
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

typedef long long ll;
typedef long double ld;

#define int ll

const ll SZ = 1e6 + 10, INF = 1e9;
ll n, m, q;
vector<ll> vec;
ll cnt_all[SZ], cnt[SZ], nxt[SZ], pr[SZ];

signed main() {
    fastInp;

    cin >> n;

    vec.resize(n);
    ll ans = 0;
    for (auto& c : vec) cin >> c;

    multiset<ll> er;

    vector<ll> vec2;
    for (int i = 0; i < n; i++) {
        er.insert(vec[i]);
        vec2.push_back(vec[i]);
        cnt_all[vec[i]]++;
    }

    sort(vec2.begin(), vec2.end());
    auto it = unique(vec2.begin(), vec2.end());
    vec2.erase(it, vec2.end());

    for (int i = 0; i < vec2.size(); i++) {
        if (i > 0) {
            pr[vec2[i]] = vec2[i - 1];
        }
        if (i < vec2.size() - 1) {
            nxt[vec2[i]] = vec2[i + 1];
        }
    }
    er.insert(INF);

    //if (er.size() != n + 1) return 1;

    while (vec.size()) {
        ans++;
        ll cur = vec.back();
        vector<ll> ltr;
        ltr.push_back(cur);
        vec.pop_back();
        ll ths = 1;
        cnt[cur]++;
        while (vec.size() > 0) {
            if (vec.back() == cur) {
                ltr.push_back(vec.back());
                cur = vec.back();
                cnt[cur]++;
                vec.pop_back();
                continue;
            }
            ll q = nxt[vec.back()];
            if (vec.size() > 0 && q == cur && (ths == 1 || cnt[cur] == cnt_all[cur])) {
                ltr.push_back(vec.back());
                cur = vec.back();
                cnt[cur]++;
                vec.pop_back();
                ths++;
            } else {
                break;
            }
        }

        for (auto c : ltr) {
            if (cnt[c] == cnt_all[c]) {
                pr[nxt[c]] = pr[c];
                nxt[pr[c]] = nxt[c];
            }
        }
    }

    //if (er.size() != 1) return 1;
    cout << ans;

    return 0;
}

Compilation message

money.cpp: In function 'int main()':
money.cpp:48:23: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for (int i = 0; i < vec2.size(); i++) {
      |                     ~~^~~~~~~~~~~~~
money.cpp:52:15: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         if (i < vec2.size() - 1) {
      |             ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 2764 KB Output is correct
38 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 460 KB Output is correct
16 Correct 0 ms 460 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 0 ms 460 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 0 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 588 KB Output is correct
26 Correct 0 ms 460 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 0 ms 332 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 460 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 2 ms 2764 KB Output is correct
38 Correct 2 ms 2764 KB Output is correct
39 Correct 232 ms 30480 KB Output is correct
40 Correct 452 ms 50044 KB Output is correct
41 Correct 175 ms 24748 KB Output is correct
42 Correct 184 ms 22072 KB Output is correct
43 Correct 128 ms 15796 KB Output is correct
44 Correct 557 ms 63060 KB Output is correct
45 Correct 516 ms 63088 KB Output is correct
46 Correct 545 ms 63120 KB Output is correct
47 Correct 416 ms 63108 KB Output is correct
48 Correct 438 ms 63024 KB Output is correct
49 Correct 862 ms 94240 KB Output is correct
50 Correct 860 ms 94284 KB Output is correct
51 Correct 921 ms 94268 KB Output is correct
52 Correct 870 ms 94180 KB Output is correct
53 Correct 879 ms 94244 KB Output is correct
54 Correct 864 ms 94288 KB Output is correct
55 Correct 1297 ms 94240 KB Output is correct
56 Correct 1293 ms 101120 KB Output is correct
57 Correct 1324 ms 101004 KB Output is correct
58 Correct 1369 ms 101020 KB Output is correct
59 Correct 1325 ms 100944 KB Output is correct
60 Correct 1312 ms 100936 KB Output is correct
61 Correct 1308 ms 100952 KB Output is correct
62 Correct 1345 ms 100956 KB Output is correct