Submission #236911

# Submission time Handle Problem Language Result Execution time Memory
236911 2020-06-03T18:46:55 Z DS007 Coin Collecting (JOI19_ho_t4) C++14
100 / 100
100 ms 14308 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int solveTestCase() {
    int n;
    cin >> n;

    vector<pair<int, int>> up, down, up_, down_;
    for (int i = 0; i < n * 2; i++) {
        int x, y;
        cin >> x >> y;

        if (y <= 1)
            down.emplace_back(x, y);
        else
            up.emplace_back(x, y);
    }

    sort(up.begin(), up.end());
    sort(down.begin(), down.end());

    int ans = 0;
    for (int i = 1, p1 = 0, p2 = 0, i1 = 1, i2 = 1; i <= n; i++) {
        while (p1 < up.size() && up[p1].first <= (i == n ? 1e9 : i))
            up_.push_back(up[p1++]);
        while (p2 < down.size() && down[p2].first <= (i == n ? 1e9 : i))
            down_.push_back(down[p2++]);

        while (i1 <= i && !up_.empty())
            ans += abs(up_.back().first - i1++) + abs(up_.back().second - 2), up_.pop_back();
        while (i2 <= i && !down_.empty())
            ans += abs(down_.back().first - i2++) + abs(down_.back().second - 1), down_.pop_back();
        while (i1 <= i && !down_.empty())
            ans += abs(down_.back().first - i1++) + abs(down_.back().second - 2), down_.pop_back();
        while (i2 <= i && !up_.empty())
            ans += abs(up_.back().first - i2++) + abs(up_.back().second - 1), up_.pop_back();
    }

    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int test = 1;
    // cin >> test;
    while (test--)
        solveTestCase();
}

Compilation message

joi2019_ho_t4.cpp: In function 'long long int solveTestCase()':
joi2019_ho_t4.cpp:25:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (p1 < up.size() && up[p1].first <= (i == n ? 1e9 : i))
                ~~~^~~~~~~~~~~
joi2019_ho_t4.cpp:27:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (p2 < down.size() && down[p2].first <= (i == n ? 1e9 : i))
                ~~~^~~~~~~~~~~~~
joi2019_ho_t4.cpp:41:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 432 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 388 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 432 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 388 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 6 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 512 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 6 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 7 ms 384 KB Output is correct
57 Correct 5 ms 512 KB Output is correct
58 Correct 5 ms 512 KB Output is correct
59 Correct 5 ms 512 KB Output is correct
60 Correct 5 ms 512 KB Output is correct
61 Correct 5 ms 512 KB Output is correct
62 Correct 5 ms 512 KB Output is correct
63 Correct 5 ms 512 KB Output is correct
64 Correct 5 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 432 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 4 ms 256 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 4 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 4 ms 384 KB Output is correct
30 Correct 4 ms 384 KB Output is correct
31 Correct 5 ms 388 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 6 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 5 ms 384 KB Output is correct
42 Correct 6 ms 384 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 6 ms 512 KB Output is correct
46 Correct 5 ms 512 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 512 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 6 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 7 ms 384 KB Output is correct
57 Correct 5 ms 512 KB Output is correct
58 Correct 5 ms 512 KB Output is correct
59 Correct 5 ms 512 KB Output is correct
60 Correct 5 ms 512 KB Output is correct
61 Correct 5 ms 512 KB Output is correct
62 Correct 5 ms 512 KB Output is correct
63 Correct 5 ms 512 KB Output is correct
64 Correct 5 ms 512 KB Output is correct
65 Correct 58 ms 5228 KB Output is correct
66 Correct 83 ms 14308 KB Output is correct
67 Correct 78 ms 6872 KB Output is correct
68 Correct 84 ms 6868 KB Output is correct
69 Correct 81 ms 6872 KB Output is correct
70 Correct 80 ms 6816 KB Output is correct
71 Correct 79 ms 6752 KB Output is correct
72 Correct 81 ms 11352 KB Output is correct
73 Correct 82 ms 11344 KB Output is correct
74 Correct 83 ms 9440 KB Output is correct
75 Correct 80 ms 9152 KB Output is correct
76 Correct 84 ms 9048 KB Output is correct
77 Correct 81 ms 8792 KB Output is correct
78 Correct 83 ms 8792 KB Output is correct
79 Correct 82 ms 8028 KB Output is correct
80 Correct 81 ms 7760 KB Output is correct
81 Correct 81 ms 8900 KB Output is correct
82 Correct 84 ms 7376 KB Output is correct
83 Correct 100 ms 7380 KB Output is correct
84 Correct 83 ms 7520 KB Output is correct
85 Correct 83 ms 7000 KB Output is correct
86 Correct 92 ms 6868 KB Output is correct
87 Correct 79 ms 6876 KB Output is correct
88 Correct 82 ms 6828 KB Output is correct
89 Correct 82 ms 7056 KB Output is correct
90 Correct 84 ms 7008 KB Output is correct
91 Correct 87 ms 6872 KB Output is correct
92 Correct 80 ms 6892 KB Output is correct
93 Correct 84 ms 7564 KB Output is correct
94 Correct 85 ms 7464 KB Output is correct
95 Correct 79 ms 6768 KB Output is correct
96 Correct 85 ms 13532 KB Output is correct
97 Correct 83 ms 12880 KB Output is correct
98 Correct 81 ms 10704 KB Output is correct
99 Correct 80 ms 10200 KB Output is correct
100 Correct 82 ms 9812 KB Output is correct
101 Correct 79 ms 9684 KB Output is correct
102 Correct 80 ms 9812 KB Output is correct
103 Correct 86 ms 9940 KB Output is correct