답안 #416082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
416082 2021-06-01T23:07:29 Z meatrow Coin Collecting (JOI19_ho_t4) C++17
37 / 100
74 ms 24228 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);
}

const int N = 1001;

ll dp[N][N];

void solve() {
    int n;
    cin >> n;
    n *= 2;
    vector<pair<ll, ll>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }
    
    sort(a.begin(), a.end());
    for (int i = 0; i <= n / 2; i++) {
        fill(dp[i], dp[i] + N, 1e18);
    }

    dp[0][0] = 0;
    for (int i = 0; i <= n / 2; i++) {
        for (int j = 0; j <= n / 2; j++) {
            if (i) {
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + abs(a[i + j - 1].first - i) + abs(a[i + j - 1].second - 1));
            }
            if (j) {
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + abs(a[i + j - 1].first - j) + abs(a[i + j - 1].second - 2));
            }
        }
    }

    cout << dp[n / 2][n / 2] << '\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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 372 KB Output is correct
10 Correct 1 ms 380 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 420 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 404 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 372 KB Output is correct
10 Correct 1 ms 380 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 420 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 404 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 16 ms 8140 KB Output is correct
35 Correct 12 ms 8140 KB Output is correct
36 Correct 12 ms 8172 KB Output is correct
37 Correct 12 ms 8140 KB Output is correct
38 Correct 16 ms 8152 KB Output is correct
39 Correct 15 ms 8220 KB Output is correct
40 Correct 12 ms 8140 KB Output is correct
41 Correct 12 ms 8220 KB Output is correct
42 Correct 12 ms 8140 KB Output is correct
43 Correct 16 ms 8224 KB Output is correct
44 Correct 12 ms 8140 KB Output is correct
45 Correct 13 ms 8160 KB Output is correct
46 Correct 14 ms 8176 KB Output is correct
47 Correct 16 ms 8224 KB Output is correct
48 Correct 16 ms 8216 KB Output is correct
49 Correct 15 ms 8212 KB Output is correct
50 Correct 15 ms 8220 KB Output is correct
51 Correct 12 ms 8220 KB Output is correct
52 Correct 12 ms 8140 KB Output is correct
53 Correct 13 ms 8140 KB Output is correct
54 Correct 12 ms 8140 KB Output is correct
55 Correct 13 ms 8220 KB Output is correct
56 Correct 16 ms 8148 KB Output is correct
57 Correct 12 ms 8140 KB Output is correct
58 Correct 11 ms 8148 KB Output is correct
59 Correct 12 ms 8140 KB Output is correct
60 Correct 13 ms 8224 KB Output is correct
61 Correct 12 ms 8240 KB Output is correct
62 Correct 13 ms 8220 KB Output is correct
63 Correct 12 ms 8160 KB Output is correct
64 Correct 13 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 372 KB Output is correct
10 Correct 1 ms 380 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 1 ms 420 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 380 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 292 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 404 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 16 ms 8140 KB Output is correct
35 Correct 12 ms 8140 KB Output is correct
36 Correct 12 ms 8172 KB Output is correct
37 Correct 12 ms 8140 KB Output is correct
38 Correct 16 ms 8152 KB Output is correct
39 Correct 15 ms 8220 KB Output is correct
40 Correct 12 ms 8140 KB Output is correct
41 Correct 12 ms 8220 KB Output is correct
42 Correct 12 ms 8140 KB Output is correct
43 Correct 16 ms 8224 KB Output is correct
44 Correct 12 ms 8140 KB Output is correct
45 Correct 13 ms 8160 KB Output is correct
46 Correct 14 ms 8176 KB Output is correct
47 Correct 16 ms 8224 KB Output is correct
48 Correct 16 ms 8216 KB Output is correct
49 Correct 15 ms 8212 KB Output is correct
50 Correct 15 ms 8220 KB Output is correct
51 Correct 12 ms 8220 KB Output is correct
52 Correct 12 ms 8140 KB Output is correct
53 Correct 13 ms 8140 KB Output is correct
54 Correct 12 ms 8140 KB Output is correct
55 Correct 13 ms 8220 KB Output is correct
56 Correct 16 ms 8148 KB Output is correct
57 Correct 12 ms 8140 KB Output is correct
58 Correct 11 ms 8148 KB Output is correct
59 Correct 12 ms 8140 KB Output is correct
60 Correct 13 ms 8224 KB Output is correct
61 Correct 12 ms 8240 KB Output is correct
62 Correct 13 ms 8220 KB Output is correct
63 Correct 12 ms 8160 KB Output is correct
64 Correct 13 ms 8140 KB Output is correct
65 Runtime error 74 ms 24228 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -