Submission #416084

# Submission time Handle Problem Language Result Execution time Memory
416084 2021-06-01T23:28:55 Z meatrow Coin Collecting (JOI19_ho_t4) C++17
8 / 100
3 ms 720 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 = 2e5 + 5;
const int K = 10;
 
ll dp[N][K * 2];
 
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;
        fill(dp[i], dp[i] + K * 2, 1e18);
    }
    fill(dp[n], dp[n] + K * 2, 1e18);
    sort(a.begin(), a.end());
 
    dp[0][K] = 0;
    for (int i = 1; i <= n; i++) {
        for (int diff = -K; diff < K; diff++) {
            int x = (i + diff) / 2;
            int y = i - x;
            if (x < 0 || x > i || y < 0 || y > i || x - y != diff) continue;
            if (diff > -K) {
                dp[i][diff + K] = min(dp[i][diff + K], dp[i - 1][diff + K - 1] + abs(a[i - 1].first - x) + abs(a[i - 1].second - 1));
            }
            if (diff + 1 < K) {
                dp[i][diff + K] = min(dp[i][diff + K], dp[i - 1][diff + K + 1] + abs(a[i - 1].first - y) + abs(a[i - 1].second - 2));
            }
        }
    }
 
    cout << dp[n][K] << '\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 1 ms 340 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 216 KB Output is correct
13 Correct 2 ms 260 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 260 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 220 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 216 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 1 ms 220 KB Output is correct
29 Correct 2 ms 220 KB Output is correct
30 Correct 1 ms 220 KB Output is correct
31 Correct 1 ms 220 KB Output is correct
32 Correct 1 ms 216 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 216 KB Output is correct
13 Correct 2 ms 260 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 260 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 220 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 216 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 1 ms 220 KB Output is correct
29 Correct 2 ms 220 KB Output is correct
30 Correct 1 ms 220 KB Output is correct
31 Correct 1 ms 220 KB Output is correct
32 Correct 1 ms 216 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 720 KB Output is correct
36 Incorrect 3 ms 700 KB Output isn't correct
37 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Correct 1 ms 216 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 2 ms 204 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 344 KB Output is correct
12 Correct 1 ms 216 KB Output is correct
13 Correct 2 ms 260 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 324 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 2 ms 260 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 2 ms 204 KB Output is correct
22 Correct 2 ms 220 KB Output is correct
23 Correct 2 ms 212 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 216 KB Output is correct
27 Correct 2 ms 212 KB Output is correct
28 Correct 1 ms 220 KB Output is correct
29 Correct 2 ms 220 KB Output is correct
30 Correct 1 ms 220 KB Output is correct
31 Correct 1 ms 220 KB Output is correct
32 Correct 1 ms 216 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 604 KB Output is correct
35 Correct 2 ms 720 KB Output is correct
36 Incorrect 3 ms 700 KB Output isn't correct
37 Halted 0 ms 0 KB -