Submission #416092

# Submission time Handle Problem Language Result Execution time Memory
416092 2021-06-02T00:14:39 Z meatrow Coin Collecting (JOI19_ho_t4) C++17
100 / 100
96 ms 5680 KB
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
const int MOD = 1e9 + 7;
 
ll binpow(ll a, ll p, int mod = MOD) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            (res *= a) %= mod;
        }
        p >>= 1;
        (a *= a) %= mod;
    }
    return res;
}
 
ll gcd(ll a, ll b) {
    return b == 0 ? a : gcd(b, a % b);
}

ll squeeze(ll& x, ll l, ll r) {
    ll res = 0;
    res += max(0LL, l - x);
    res += max(0LL, x - r);
    x = max(x, l);
    x = min(x, r);
    return res;
}

const int N = 2e5 + 2;

int cnt[N][2];

void solve() {
    int n;
    cin >> n;
    ll ans = 0;
    for (int i = 0; i < n * 2; i++) {
        ll x, y;
        cin >> x >> y;
        x--, y--;
        ans += squeeze(x, 0, n - 1);
        ans += squeeze(y, 0, 1);
        cnt[x][y]++;
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 2; j++) {
            if (cnt[i][j] > 1) {
                int delta = min(cnt[i][j] - 1, 1 - cnt[i][j ^ 1]);
                delta = max(delta, 0);
                ans += delta;
                cnt[i][j] -= delta;
                cnt[i][j ^ 1] += delta;
            }
        }

        cnt[i + 1][0] += cnt[i][0] - 1;
        cnt[i + 1][1] += cnt[i][1] - 1;
        ans += abs(cnt[i][0] - 1);
        ans += abs(cnt[i][1] - 1);
    }
    
    cout << ans << '\n';
}
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1;
    // cin >> T;
    for (int tc = 1; tc <= T; tc++) {
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 260 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 368 KB Output is correct
10 Correct 1 ms 220 KB Output is correct
11 Correct 1 ms 220 KB Output is correct
12 Correct 2 ms 220 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 368 KB Output is correct
19 Correct 2 ms 220 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 220 KB Output is correct
22 Correct 2 ms 272 KB Output is correct
23 Correct 3 ms 220 KB Output is correct
24 Correct 1 ms 220 KB Output is correct
25 Correct 1 ms 220 KB Output is correct
26 Correct 2 ms 220 KB Output is correct
27 Correct 1 ms 220 KB Output is correct
28 Correct 2 ms 220 KB Output is correct
29 Correct 2 ms 220 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 320 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 260 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 368 KB Output is correct
10 Correct 1 ms 220 KB Output is correct
11 Correct 1 ms 220 KB Output is correct
12 Correct 2 ms 220 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 368 KB Output is correct
19 Correct 2 ms 220 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 220 KB Output is correct
22 Correct 2 ms 272 KB Output is correct
23 Correct 3 ms 220 KB Output is correct
24 Correct 1 ms 220 KB Output is correct
25 Correct 1 ms 220 KB Output is correct
26 Correct 2 ms 220 KB Output is correct
27 Correct 1 ms 220 KB Output is correct
28 Correct 2 ms 220 KB Output is correct
29 Correct 2 ms 220 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 320 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 220 KB Output is correct
34 Correct 1 ms 368 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 344 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 372 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 3 ms 372 KB Output is correct
50 Correct 3 ms 332 KB Output is correct
51 Correct 3 ms 340 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 2 ms 364 KB Output is correct
56 Correct 2 ms 372 KB Output is correct
57 Correct 3 ms 428 KB Output is correct
58 Correct 2 ms 360 KB Output is correct
59 Correct 2 ms 344 KB Output is correct
60 Correct 2 ms 364 KB Output is correct
61 Correct 2 ms 332 KB Output is correct
62 Correct 3 ms 360 KB Output is correct
63 Correct 3 ms 340 KB Output is correct
64 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 260 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 376 KB Output is correct
8 Correct 2 ms 380 KB Output is correct
9 Correct 2 ms 368 KB Output is correct
10 Correct 1 ms 220 KB Output is correct
11 Correct 1 ms 220 KB Output is correct
12 Correct 2 ms 220 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 2 ms 308 KB Output is correct
17 Correct 2 ms 344 KB Output is correct
18 Correct 2 ms 368 KB Output is correct
19 Correct 2 ms 220 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 220 KB Output is correct
22 Correct 2 ms 272 KB Output is correct
23 Correct 3 ms 220 KB Output is correct
24 Correct 1 ms 220 KB Output is correct
25 Correct 1 ms 220 KB Output is correct
26 Correct 2 ms 220 KB Output is correct
27 Correct 1 ms 220 KB Output is correct
28 Correct 2 ms 220 KB Output is correct
29 Correct 2 ms 220 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 2 ms 320 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 1 ms 220 KB Output is correct
34 Correct 1 ms 368 KB Output is correct
35 Correct 3 ms 348 KB Output is correct
36 Correct 2 ms 348 KB Output is correct
37 Correct 3 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 2 ms 332 KB Output is correct
40 Correct 2 ms 344 KB Output is correct
41 Correct 2 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 332 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 332 KB Output is correct
47 Correct 2 ms 372 KB Output is correct
48 Correct 2 ms 332 KB Output is correct
49 Correct 3 ms 372 KB Output is correct
50 Correct 3 ms 332 KB Output is correct
51 Correct 3 ms 340 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 340 KB Output is correct
55 Correct 2 ms 364 KB Output is correct
56 Correct 2 ms 372 KB Output is correct
57 Correct 3 ms 428 KB Output is correct
58 Correct 2 ms 360 KB Output is correct
59 Correct 2 ms 344 KB Output is correct
60 Correct 2 ms 364 KB Output is correct
61 Correct 2 ms 332 KB Output is correct
62 Correct 3 ms 360 KB Output is correct
63 Correct 3 ms 340 KB Output is correct
64 Correct 2 ms 340 KB Output is correct
65 Correct 56 ms 2648 KB Output is correct
66 Correct 92 ms 5680 KB Output is correct
67 Correct 87 ms 4100 KB Output is correct
68 Correct 68 ms 4292 KB Output is correct
69 Correct 71 ms 4280 KB Output is correct
70 Correct 75 ms 4280 KB Output is correct
71 Correct 75 ms 4284 KB Output is correct
72 Correct 66 ms 4300 KB Output is correct
73 Correct 59 ms 4296 KB Output is correct
74 Correct 59 ms 4308 KB Output is correct
75 Correct 56 ms 4152 KB Output is correct
76 Correct 59 ms 4284 KB Output is correct
77 Correct 74 ms 4068 KB Output is correct
78 Correct 64 ms 3552 KB Output is correct
79 Correct 57 ms 4300 KB Output is correct
80 Correct 63 ms 4076 KB Output is correct
81 Correct 61 ms 4252 KB Output is correct
82 Correct 63 ms 3940 KB Output is correct
83 Correct 64 ms 3664 KB Output is correct
84 Correct 60 ms 3152 KB Output is correct
85 Correct 71 ms 4228 KB Output is correct
86 Correct 60 ms 4276 KB Output is correct
87 Correct 72 ms 4280 KB Output is correct
88 Correct 65 ms 4284 KB Output is correct
89 Correct 74 ms 4280 KB Output is correct
90 Correct 73 ms 4284 KB Output is correct
91 Correct 71 ms 4284 KB Output is correct
92 Correct 96 ms 4196 KB Output is correct
93 Correct 63 ms 4112 KB Output is correct
94 Correct 56 ms 5256 KB Output is correct
95 Correct 78 ms 3548 KB Output is correct
96 Correct 72 ms 4308 KB Output is correct
97 Correct 63 ms 4340 KB Output is correct
98 Correct 66 ms 4220 KB Output is correct
99 Correct 69 ms 4292 KB Output is correct
100 Correct 60 ms 4272 KB Output is correct
101 Correct 60 ms 4180 KB Output is correct
102 Correct 66 ms 4276 KB Output is correct
103 Correct 67 ms 4248 KB Output is correct