Submission #367118

# Submission time Handle Problem Language Result Execution time Memory
367118 2021-02-16T10:20:21 Z Lam_lai_cuoc_doi Coin Collecting (JOI19_ho_t4) C++17
37 / 100
15 ms 8448 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;

const bool typetest = 0;
const int N = 1e3 + 5;
const ll Inf = 1e17;
pair<ll, ll> a[N * 2];
int n;
ll dp[N][N];

void Read()
{
    cin >> n;
    for (int i = 1; i <= n * 2; ++i)
        cin >> a[i].first >> a[i].second;
    sort(a + 1, a + n * 2 + 1);
}

inline void Min(ll &x, ll y)
{
    if (x > y)
        x = y;
}

void Solve()
{
    fill_n(&dp[0][0], N * N, Inf);
    dp[0][0] = 0;
    for (int i = 0; i <= n; ++i)
        for (int j = 0; j <= n; ++j)
        {
            if (i < n)
                Min(dp[i + 1][j], dp[i][j] + abs(a[i + j + 1].first - i - 1) + abs(a[i + j + 1].second - 1));
            if (j < n)
                Min(dp[i][j + 1], dp[i][j] + abs(a[i + j + 1].first - j - 1) + abs(a[i + j + 1].second - 2));
        }
    cout << dp[n][n];
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t(1);
    if (typetest)
        cin >> t;
    for (int _ = 1; _ <= t; ++_)
    {
        Read();
        Solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 5 ms 8300 KB Output is correct
3 Correct 5 ms 8300 KB Output is correct
4 Correct 5 ms 8300 KB Output is correct
5 Correct 5 ms 8300 KB Output is correct
6 Correct 5 ms 8300 KB Output is correct
7 Correct 5 ms 8300 KB Output is correct
8 Correct 5 ms 8300 KB Output is correct
9 Correct 6 ms 8300 KB Output is correct
10 Correct 7 ms 8300 KB Output is correct
11 Correct 7 ms 8300 KB Output is correct
12 Correct 7 ms 8300 KB Output is correct
13 Correct 6 ms 8300 KB Output is correct
14 Correct 5 ms 8300 KB Output is correct
15 Correct 5 ms 8300 KB Output is correct
16 Correct 5 ms 8300 KB Output is correct
17 Correct 5 ms 8300 KB Output is correct
18 Correct 5 ms 8300 KB Output is correct
19 Correct 5 ms 8300 KB Output is correct
20 Correct 5 ms 8300 KB Output is correct
21 Correct 5 ms 8300 KB Output is correct
22 Correct 5 ms 8300 KB Output is correct
23 Correct 5 ms 8300 KB Output is correct
24 Correct 5 ms 8300 KB Output is correct
25 Correct 7 ms 8300 KB Output is correct
26 Correct 7 ms 8300 KB Output is correct
27 Correct 6 ms 8192 KB Output is correct
28 Correct 7 ms 8300 KB Output is correct
29 Correct 5 ms 8300 KB Output is correct
30 Correct 5 ms 8300 KB Output is correct
31 Correct 5 ms 8300 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 7 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 5 ms 8300 KB Output is correct
3 Correct 5 ms 8300 KB Output is correct
4 Correct 5 ms 8300 KB Output is correct
5 Correct 5 ms 8300 KB Output is correct
6 Correct 5 ms 8300 KB Output is correct
7 Correct 5 ms 8300 KB Output is correct
8 Correct 5 ms 8300 KB Output is correct
9 Correct 6 ms 8300 KB Output is correct
10 Correct 7 ms 8300 KB Output is correct
11 Correct 7 ms 8300 KB Output is correct
12 Correct 7 ms 8300 KB Output is correct
13 Correct 6 ms 8300 KB Output is correct
14 Correct 5 ms 8300 KB Output is correct
15 Correct 5 ms 8300 KB Output is correct
16 Correct 5 ms 8300 KB Output is correct
17 Correct 5 ms 8300 KB Output is correct
18 Correct 5 ms 8300 KB Output is correct
19 Correct 5 ms 8300 KB Output is correct
20 Correct 5 ms 8300 KB Output is correct
21 Correct 5 ms 8300 KB Output is correct
22 Correct 5 ms 8300 KB Output is correct
23 Correct 5 ms 8300 KB Output is correct
24 Correct 5 ms 8300 KB Output is correct
25 Correct 7 ms 8300 KB Output is correct
26 Correct 7 ms 8300 KB Output is correct
27 Correct 6 ms 8192 KB Output is correct
28 Correct 7 ms 8300 KB Output is correct
29 Correct 5 ms 8300 KB Output is correct
30 Correct 5 ms 8300 KB Output is correct
31 Correct 5 ms 8300 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 7 ms 8300 KB Output is correct
34 Correct 13 ms 8300 KB Output is correct
35 Correct 12 ms 8300 KB Output is correct
36 Correct 12 ms 8352 KB Output is correct
37 Correct 11 ms 8300 KB Output is correct
38 Correct 15 ms 8300 KB Output is correct
39 Correct 14 ms 8300 KB Output is correct
40 Correct 11 ms 8300 KB Output is correct
41 Correct 11 ms 8300 KB Output is correct
42 Correct 11 ms 8300 KB Output is correct
43 Correct 12 ms 8428 KB Output is correct
44 Correct 11 ms 8300 KB Output is correct
45 Correct 14 ms 8300 KB Output is correct
46 Correct 12 ms 8300 KB Output is correct
47 Correct 11 ms 8300 KB Output is correct
48 Correct 14 ms 8300 KB Output is correct
49 Correct 14 ms 8448 KB Output is correct
50 Correct 11 ms 8300 KB Output is correct
51 Correct 11 ms 8300 KB Output is correct
52 Correct 11 ms 8300 KB Output is correct
53 Correct 11 ms 8300 KB Output is correct
54 Correct 11 ms 8300 KB Output is correct
55 Correct 13 ms 8300 KB Output is correct
56 Correct 11 ms 8300 KB Output is correct
57 Correct 13 ms 8300 KB Output is correct
58 Correct 12 ms 8336 KB Output is correct
59 Correct 14 ms 8352 KB Output is correct
60 Correct 13 ms 8300 KB Output is correct
61 Correct 15 ms 8300 KB Output is correct
62 Correct 11 ms 8300 KB Output is correct
63 Correct 11 ms 8300 KB Output is correct
64 Correct 11 ms 8300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 5 ms 8300 KB Output is correct
3 Correct 5 ms 8300 KB Output is correct
4 Correct 5 ms 8300 KB Output is correct
5 Correct 5 ms 8300 KB Output is correct
6 Correct 5 ms 8300 KB Output is correct
7 Correct 5 ms 8300 KB Output is correct
8 Correct 5 ms 8300 KB Output is correct
9 Correct 6 ms 8300 KB Output is correct
10 Correct 7 ms 8300 KB Output is correct
11 Correct 7 ms 8300 KB Output is correct
12 Correct 7 ms 8300 KB Output is correct
13 Correct 6 ms 8300 KB Output is correct
14 Correct 5 ms 8300 KB Output is correct
15 Correct 5 ms 8300 KB Output is correct
16 Correct 5 ms 8300 KB Output is correct
17 Correct 5 ms 8300 KB Output is correct
18 Correct 5 ms 8300 KB Output is correct
19 Correct 5 ms 8300 KB Output is correct
20 Correct 5 ms 8300 KB Output is correct
21 Correct 5 ms 8300 KB Output is correct
22 Correct 5 ms 8300 KB Output is correct
23 Correct 5 ms 8300 KB Output is correct
24 Correct 5 ms 8300 KB Output is correct
25 Correct 7 ms 8300 KB Output is correct
26 Correct 7 ms 8300 KB Output is correct
27 Correct 6 ms 8192 KB Output is correct
28 Correct 7 ms 8300 KB Output is correct
29 Correct 5 ms 8300 KB Output is correct
30 Correct 5 ms 8300 KB Output is correct
31 Correct 5 ms 8300 KB Output is correct
32 Correct 5 ms 8300 KB Output is correct
33 Correct 7 ms 8300 KB Output is correct
34 Correct 13 ms 8300 KB Output is correct
35 Correct 12 ms 8300 KB Output is correct
36 Correct 12 ms 8352 KB Output is correct
37 Correct 11 ms 8300 KB Output is correct
38 Correct 15 ms 8300 KB Output is correct
39 Correct 14 ms 8300 KB Output is correct
40 Correct 11 ms 8300 KB Output is correct
41 Correct 11 ms 8300 KB Output is correct
42 Correct 11 ms 8300 KB Output is correct
43 Correct 12 ms 8428 KB Output is correct
44 Correct 11 ms 8300 KB Output is correct
45 Correct 14 ms 8300 KB Output is correct
46 Correct 12 ms 8300 KB Output is correct
47 Correct 11 ms 8300 KB Output is correct
48 Correct 14 ms 8300 KB Output is correct
49 Correct 14 ms 8448 KB Output is correct
50 Correct 11 ms 8300 KB Output is correct
51 Correct 11 ms 8300 KB Output is correct
52 Correct 11 ms 8300 KB Output is correct
53 Correct 11 ms 8300 KB Output is correct
54 Correct 11 ms 8300 KB Output is correct
55 Correct 13 ms 8300 KB Output is correct
56 Correct 11 ms 8300 KB Output is correct
57 Correct 13 ms 8300 KB Output is correct
58 Correct 12 ms 8336 KB Output is correct
59 Correct 14 ms 8352 KB Output is correct
60 Correct 13 ms 8300 KB Output is correct
61 Correct 15 ms 8300 KB Output is correct
62 Correct 11 ms 8300 KB Output is correct
63 Correct 11 ms 8300 KB Output is correct
64 Correct 11 ms 8300 KB Output is correct
65 Runtime error 2 ms 816 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -