Submission #888970

# Submission time Handle Problem Language Result Execution time Memory
888970 2023-12-18T13:57:59 Z hafo Coin Collecting (JOI19_ho_t4) C++14
37 / 100
193 ms 69124 KB
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pb push_back
#define pa pair<int, int>
#define pall pair<ll, int>
#define fi first
#define se second
#define TASK "test"
#define Size(x) (int) x.size()
#define all(x) x.begin(), x.end()
using namespace std;

template<typename T1, typename T2> bool mini (T1 &a, T2 b) {if(a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maxi (T1 &a, T2 b) {if(a < b) a = b; else return 0; return 1;}

const int MOD = 1e9 + 7;
const int LOG = 20;
const int maxn = 2e5 + 7;
const ll oo = 1e18 + 69;

int n;
pa a[maxn];

struct sub2 {
    static const int maxn = 2e3 + 7;
    ll dp[maxn][maxn];

    void solve() {
        sort(a + 1, a + 1 + n);
        for(int i = 0; i <= n; i++) {
            for(int j = 0; j <= n; j++) dp[i][j] = oo;
        }

        dp[0][0] = 0;
        for(int i = 1; i <= n; i++) {
            for(int j = 0; j <= min(i, n / 2); j++) {
                int rem = i - j;
                if(rem > n / 2) continue;
                if(j > 0) {
                    mini(dp[i][j], dp[i - 1][j - 1] + abs(a[i].fi - j) + abs(a[i].se - 1));
                }
                if(rem > 0) {
                    mini(dp[i][j], dp[i - 1][j] + abs(a[i].fi - rem) + abs(a[i].se - 2));
                }
            }
        }
        cout<<dp[n][n / 2];
    }

} sub2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //freopen(TASK".inp", "r", stdin);
    //freopen(TASK".out", "w", stdout);

    cin>>n;
    n *= 2;
    for(int i = 1; i <= n; i++) cin>>a[i].fi>>a[i].se;
    sub2.solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4596 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4552 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4692 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4596 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4552 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4692 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 12 ms 33372 KB Output is correct
35 Correct 10 ms 33368 KB Output is correct
36 Correct 9 ms 33260 KB Output is correct
37 Correct 10 ms 33372 KB Output is correct
38 Correct 9 ms 33500 KB Output is correct
39 Correct 9 ms 33476 KB Output is correct
40 Correct 11 ms 33368 KB Output is correct
41 Correct 9 ms 33372 KB Output is correct
42 Correct 10 ms 33268 KB Output is correct
43 Correct 10 ms 33752 KB Output is correct
44 Correct 10 ms 33372 KB Output is correct
45 Correct 9 ms 33508 KB Output is correct
46 Correct 9 ms 33372 KB Output is correct
47 Correct 10 ms 33504 KB Output is correct
48 Correct 9 ms 33504 KB Output is correct
49 Correct 10 ms 33372 KB Output is correct
50 Correct 9 ms 33372 KB Output is correct
51 Correct 9 ms 33368 KB Output is correct
52 Correct 9 ms 33368 KB Output is correct
53 Correct 9 ms 33372 KB Output is correct
54 Correct 9 ms 33372 KB Output is correct
55 Correct 10 ms 33372 KB Output is correct
56 Correct 13 ms 33564 KB Output is correct
57 Correct 9 ms 33624 KB Output is correct
58 Correct 9 ms 33504 KB Output is correct
59 Correct 9 ms 33496 KB Output is correct
60 Correct 9 ms 33504 KB Output is correct
61 Correct 9 ms 33372 KB Output is correct
62 Correct 9 ms 33372 KB Output is correct
63 Correct 9 ms 33372 KB Output is correct
64 Correct 9 ms 33372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4696 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4596 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4552 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4440 KB Output is correct
29 Correct 1 ms 4692 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 12 ms 33372 KB Output is correct
35 Correct 10 ms 33368 KB Output is correct
36 Correct 9 ms 33260 KB Output is correct
37 Correct 10 ms 33372 KB Output is correct
38 Correct 9 ms 33500 KB Output is correct
39 Correct 9 ms 33476 KB Output is correct
40 Correct 11 ms 33368 KB Output is correct
41 Correct 9 ms 33372 KB Output is correct
42 Correct 10 ms 33268 KB Output is correct
43 Correct 10 ms 33752 KB Output is correct
44 Correct 10 ms 33372 KB Output is correct
45 Correct 9 ms 33508 KB Output is correct
46 Correct 9 ms 33372 KB Output is correct
47 Correct 10 ms 33504 KB Output is correct
48 Correct 9 ms 33504 KB Output is correct
49 Correct 10 ms 33372 KB Output is correct
50 Correct 9 ms 33372 KB Output is correct
51 Correct 9 ms 33368 KB Output is correct
52 Correct 9 ms 33368 KB Output is correct
53 Correct 9 ms 33372 KB Output is correct
54 Correct 9 ms 33372 KB Output is correct
55 Correct 10 ms 33372 KB Output is correct
56 Correct 13 ms 33564 KB Output is correct
57 Correct 9 ms 33624 KB Output is correct
58 Correct 9 ms 33504 KB Output is correct
59 Correct 9 ms 33496 KB Output is correct
60 Correct 9 ms 33504 KB Output is correct
61 Correct 9 ms 33372 KB Output is correct
62 Correct 9 ms 33372 KB Output is correct
63 Correct 9 ms 33372 KB Output is correct
64 Correct 9 ms 33372 KB Output is correct
65 Runtime error 193 ms 69124 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -