Submission #384780

# Submission time Handle Problem Language Result Execution time Memory
384780 2021-04-02T09:15:13 Z valerikk Coin Collecting (JOI19_ho_t4) C++17
37 / 100
14 ms 12652 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1005;

int n;
int x[2 * N], y[2 * N];
ll ans = 0;
ll d[2 * N][2 * N];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < 2 * n; i++) {
        cin >> x[i] >> y[i];
        if (x[i] < 1) {
            ans += 1 - x[i];
            x[i] = 1;
        }
        if (x[i] > n) {
            ans += x[i] - n;
            x[i] = n;
        }
        if (y[i] < 1) {
            ans += 1 - y[i];
            y[i] = 1;
        }
        if (y[i] > 2) {
            ans += y[i] - 2;
            y[i] = 2;
        }
        x[i]--;
        y[i]--;
    }
    
    vector<int> q, w;
    for (int i = 0; i < 2 * n; i++) {
        if (y[i] == 0) {
            q.push_back(x[i]);
        } else {
            w.push_back(x[i]);
        }
    }
    
    sort(q.begin(), q.end());
    sort(w.begin(), w.end());
    int qq = q.size(), ww = w.size();
    
    for (int i = 0; i <= qq; i++) {
        for (int j = 0; j <= ww; j++) d[i][j] = 1e18;
    }
    d[0][0] = 0;
    for (int i = 0; i <= qq; i++) {
        for (int j = 0; j <= ww; j++) {
            int xx = (i + j) / 2, yy = (i + j) % 2;
            if (i < qq) {
                d[i + 1][j] = min(d[i + 1][j], d[i][j] + abs(xx - q[i]) + yy);
            }
            if (j < ww) {
                d[i][j + 1] = min(d[i][j + 1], d[i][j] + abs(xx - w[j]) + 1 - yy);
            }
        }
    }
    ans += d[qq][ww];
    
    cout << ans << endl; 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 14 ms 12268 KB Output is correct
35 Correct 6 ms 8428 KB Output is correct
36 Correct 14 ms 12140 KB Output is correct
37 Correct 14 ms 12268 KB Output is correct
38 Correct 14 ms 12268 KB Output is correct
39 Correct 14 ms 12396 KB Output is correct
40 Correct 14 ms 12268 KB Output is correct
41 Correct 14 ms 12268 KB Output is correct
42 Correct 14 ms 12268 KB Output is correct
43 Correct 14 ms 12268 KB Output is correct
44 Correct 14 ms 12268 KB Output is correct
45 Correct 14 ms 12268 KB Output is correct
46 Correct 14 ms 12396 KB Output is correct
47 Correct 14 ms 12268 KB Output is correct
48 Correct 14 ms 12396 KB Output is correct
49 Correct 14 ms 12268 KB Output is correct
50 Correct 14 ms 12268 KB Output is correct
51 Correct 14 ms 12268 KB Output is correct
52 Correct 14 ms 12268 KB Output is correct
53 Correct 6 ms 8428 KB Output is correct
54 Correct 9 ms 10348 KB Output is correct
55 Correct 5 ms 3180 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 6 ms 3564 KB Output is correct
58 Correct 13 ms 10860 KB Output is correct
59 Correct 13 ms 12652 KB Output is correct
60 Correct 14 ms 12652 KB Output is correct
61 Correct 13 ms 11244 KB Output is correct
62 Correct 12 ms 10604 KB Output is correct
63 Correct 14 ms 10092 KB Output is correct
64 Correct 10 ms 7916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 364 KB Output is correct
34 Correct 14 ms 12268 KB Output is correct
35 Correct 6 ms 8428 KB Output is correct
36 Correct 14 ms 12140 KB Output is correct
37 Correct 14 ms 12268 KB Output is correct
38 Correct 14 ms 12268 KB Output is correct
39 Correct 14 ms 12396 KB Output is correct
40 Correct 14 ms 12268 KB Output is correct
41 Correct 14 ms 12268 KB Output is correct
42 Correct 14 ms 12268 KB Output is correct
43 Correct 14 ms 12268 KB Output is correct
44 Correct 14 ms 12268 KB Output is correct
45 Correct 14 ms 12268 KB Output is correct
46 Correct 14 ms 12396 KB Output is correct
47 Correct 14 ms 12268 KB Output is correct
48 Correct 14 ms 12396 KB Output is correct
49 Correct 14 ms 12268 KB Output is correct
50 Correct 14 ms 12268 KB Output is correct
51 Correct 14 ms 12268 KB Output is correct
52 Correct 14 ms 12268 KB Output is correct
53 Correct 6 ms 8428 KB Output is correct
54 Correct 9 ms 10348 KB Output is correct
55 Correct 5 ms 3180 KB Output is correct
56 Correct 2 ms 364 KB Output is correct
57 Correct 6 ms 3564 KB Output is correct
58 Correct 13 ms 10860 KB Output is correct
59 Correct 13 ms 12652 KB Output is correct
60 Correct 14 ms 12652 KB Output is correct
61 Correct 13 ms 11244 KB Output is correct
62 Correct 12 ms 10604 KB Output is correct
63 Correct 14 ms 10092 KB Output is correct
64 Correct 10 ms 7916 KB Output is correct
65 Runtime error 4 ms 652 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -