Submission #127689

# Submission time Handle Problem Language Result Execution time Memory
127689 2019-07-10T00:59:31 Z tri Coin Collecting (JOI19_ho_t4) C++14
100 / 100
348 ms 8952 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

namespace debug {
    const int DEBUG = true;

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x);

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x);

    template<class T>
    void pr(const vector<T> &x);

    template<class T>
    void pr(const set<T> &x);

    template<class T1, class T2>
    void pr(const map<T1, T2> &x);

    template<class T>
    void pr(const T &x) { if (DEBUG) cout << x; }

    template<class T, class... Ts>
    void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }

    template<class T1, class T2>
    void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }

    template<class T>
    void prIn(const T &x) {
        pr("{");
        bool fst = 1;
        for (auto &a : x) {
            pr(fst ? "" : ", ", a), fst = 0;
        }
        pr("}");
    }

    template<class T, size_t SZ>
    void pr(const array<T, SZ> &x) { prIn(x); }

    template<class T>
    void pr(const vector<T> &x) { prIn(x); }

    template<class T>
    void pr(const set<T> &x) { prIn(x); }

    template<class T1, class T2>
    void pr(const map<T1, T2> &x) { prIn(x); }

    void ps() { pr("\n"); }

    template<class Arg, class... Args>
    void ps(const Arg &first, const Args &... rest) {
        pr(first, " ");
        ps(rest...);
    }
}
using namespace debug;


int main() {
    int N;
    cin >> N;
    vector<pl> pts(2 * N);
    for (int i = 0; i < 2 * N; i++) {
        cin >> pts[i].f;
        cin >> pts[i].s;
    }

    vector<vi> grid(2);
    grid[0].resize(N);
    grid[1].resize(N);

    ll ans = 0;
    for (int i = 0; i < 2 * N; i++) {
        if (pts[i].s > 2) {
            ans += pts[i].s - 2;
            pts[i].s = 2;
        } else if (pts[i].s < 1) {
            ans += 1 - pts[i].s;
            pts[i].s = 1;
        }

        if (pts[i].f < 1) {
            ans += 1 - pts[i].f;
            pts[i].f = 1;
        } else if (pts[i].f > N) {
            ans += pts[i].f - N;
            pts[i].f = N;
        }
//        cout << pts[i].s - 1 << " " << pts[i].f - 1 << endl;
        grid[2 - pts[i].s][pts[i].f - 1]++;
    }

    // ps(grid);

    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            grid[i][j]--;
        }
    }

    // ps(grid);

    int u = 0;
    int l = 0;
    for (int i = 0; i < N; i++) {
        ans += abs(u) + abs(l);
        u += grid[0][i];
        l += grid[1][i];
        if (u > 0 && l < 0) {
            int d = min(u, -l);
            u -= d;
            l += d;
            ans += d;
        }
        if (u < 0 && l > 0) {
            int d = min(-u, l);
            u += d;
            l -= d;
            ans += d;
        }
        //ps(u, l);
    }
    cout << ans << endl;
//    cout << u << l << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 4 ms 376 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 4 ms 376 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 4 ms 376 KB Output is correct
42 Correct 4 ms 376 KB Output is correct
43 Correct 4 ms 376 KB Output is correct
44 Correct 4 ms 376 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 4 ms 376 KB Output is correct
47 Correct 4 ms 372 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 4 ms 376 KB Output is correct
50 Correct 4 ms 376 KB Output is correct
51 Correct 4 ms 376 KB Output is correct
52 Correct 4 ms 376 KB Output is correct
53 Correct 4 ms 376 KB Output is correct
54 Correct 4 ms 376 KB Output is correct
55 Correct 4 ms 376 KB Output is correct
56 Correct 4 ms 376 KB Output is correct
57 Correct 4 ms 376 KB Output is correct
58 Correct 4 ms 376 KB Output is correct
59 Correct 4 ms 376 KB Output is correct
60 Correct 4 ms 376 KB Output is correct
61 Correct 4 ms 376 KB Output is correct
62 Correct 4 ms 376 KB Output is correct
63 Correct 4 ms 376 KB Output is correct
64 Correct 4 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 252 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 392 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 256 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 256 KB Output is correct
34 Correct 3 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 4 ms 376 KB Output is correct
37 Correct 4 ms 376 KB Output is correct
38 Correct 4 ms 376 KB Output is correct
39 Correct 4 ms 376 KB Output is correct
40 Correct 4 ms 376 KB Output is correct
41 Correct 4 ms 376 KB Output is correct
42 Correct 4 ms 376 KB Output is correct
43 Correct 4 ms 376 KB Output is correct
44 Correct 4 ms 376 KB Output is correct
45 Correct 4 ms 376 KB Output is correct
46 Correct 4 ms 376 KB Output is correct
47 Correct 4 ms 372 KB Output is correct
48 Correct 4 ms 376 KB Output is correct
49 Correct 4 ms 376 KB Output is correct
50 Correct 4 ms 376 KB Output is correct
51 Correct 4 ms 376 KB Output is correct
52 Correct 4 ms 376 KB Output is correct
53 Correct 4 ms 376 KB Output is correct
54 Correct 4 ms 376 KB Output is correct
55 Correct 4 ms 376 KB Output is correct
56 Correct 4 ms 376 KB Output is correct
57 Correct 4 ms 376 KB Output is correct
58 Correct 4 ms 376 KB Output is correct
59 Correct 4 ms 376 KB Output is correct
60 Correct 4 ms 376 KB Output is correct
61 Correct 4 ms 376 KB Output is correct
62 Correct 4 ms 376 KB Output is correct
63 Correct 4 ms 376 KB Output is correct
64 Correct 4 ms 376 KB Output is correct
65 Correct 157 ms 5820 KB Output is correct
66 Correct 348 ms 8952 KB Output is correct
67 Correct 257 ms 7484 KB Output is correct
68 Correct 257 ms 7416 KB Output is correct
69 Correct 262 ms 7544 KB Output is correct
70 Correct 265 ms 7468 KB Output is correct
71 Correct 256 ms 7416 KB Output is correct
72 Correct 257 ms 7456 KB Output is correct
73 Correct 257 ms 7420 KB Output is correct
74 Correct 260 ms 7416 KB Output is correct
75 Correct 260 ms 7416 KB Output is correct
76 Correct 261 ms 7464 KB Output is correct
77 Correct 253 ms 7416 KB Output is correct
78 Correct 256 ms 7416 KB Output is correct
79 Correct 256 ms 7416 KB Output is correct
80 Correct 271 ms 7544 KB Output is correct
81 Correct 272 ms 7416 KB Output is correct
82 Correct 256 ms 7416 KB Output is correct
83 Correct 257 ms 7516 KB Output is correct
84 Correct 257 ms 7416 KB Output is correct
85 Correct 257 ms 7416 KB Output is correct
86 Correct 256 ms 7540 KB Output is correct
87 Correct 258 ms 7544 KB Output is correct
88 Correct 255 ms 7516 KB Output is correct
89 Correct 256 ms 7516 KB Output is correct
90 Correct 260 ms 7412 KB Output is correct
91 Correct 259 ms 7484 KB Output is correct
92 Correct 276 ms 7576 KB Output is correct
93 Correct 266 ms 7544 KB Output is correct
94 Correct 250 ms 7328 KB Output is correct
95 Correct 260 ms 7416 KB Output is correct
96 Correct 269 ms 7460 KB Output is correct
97 Correct 260 ms 7540 KB Output is correct
98 Correct 266 ms 7452 KB Output is correct
99 Correct 260 ms 7548 KB Output is correct
100 Correct 284 ms 7572 KB Output is correct
101 Correct 257 ms 7508 KB Output is correct
102 Correct 266 ms 7416 KB Output is correct
103 Correct 258 ms 7416 KB Output is correct