답안 #587046

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587046 2022-07-01T09:12:13 Z Justin1 Coin Collecting (JOI19_ho_t4) C++14
8 / 100
284 ms 16784 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;

struct pt{
    ll x, y;
};

ll n,m,k,x,y,z;
ll dp[2 << 21], dig[2 << 21];
pt ar[200005], tar[200005];

void cal(ll x, ll & y) {
    while (x) x &= x-1, y++;
}

int dis(pt x, pt y) {
    return abs(x.x - y.x) + abs(x.y - y.y);
}

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) tar[i] = {i,1};
    for (int i = 1; i <= n; i++) tar[i+n] = {i,2};
    n *= 2;
    for (int i = 1; i <= n; i++) {
        cin >> ar[i].x >> ar[i].y;
    }
    for (int i = 1; i < 1 << n; i++) cal(i,dig[i]);
    for (int c = 1; c <= n; c++) {
        for (int i = 1; i < 1 << n; i++) {
            if (dig[i] != c) continue;
            dp[i] = 1e18;
            for (int j = 1; j <= n; j++) {
                if (~i & (1 << (j-1))) continue;
                dp[i] = min(dp[i],dis(tar[c],ar[j]) + dp[i ^ (1 << (j-1))]);
            }
        }
    }
    cout << dp[(1 << n) - 1] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 116 ms 16664 KB Output is correct
5 Correct 117 ms 16724 KB Output is correct
6 Correct 121 ms 16732 KB Output is correct
7 Correct 135 ms 16688 KB Output is correct
8 Correct 126 ms 16732 KB Output is correct
9 Correct 111 ms 16716 KB Output is correct
10 Correct 117 ms 16684 KB Output is correct
11 Correct 121 ms 16692 KB Output is correct
12 Correct 121 ms 16732 KB Output is correct
13 Correct 118 ms 16668 KB Output is correct
14 Correct 143 ms 16716 KB Output is correct
15 Correct 128 ms 16776 KB Output is correct
16 Correct 122 ms 16628 KB Output is correct
17 Correct 134 ms 16688 KB Output is correct
18 Correct 127 ms 16728 KB Output is correct
19 Correct 122 ms 16632 KB Output is correct
20 Correct 126 ms 16728 KB Output is correct
21 Correct 113 ms 16728 KB Output is correct
22 Correct 114 ms 16624 KB Output is correct
23 Correct 125 ms 16708 KB Output is correct
24 Correct 114 ms 16784 KB Output is correct
25 Correct 111 ms 16724 KB Output is correct
26 Correct 111 ms 16640 KB Output is correct
27 Correct 110 ms 16684 KB Output is correct
28 Correct 127 ms 16728 KB Output is correct
29 Correct 112 ms 16716 KB Output is correct
30 Correct 112 ms 16740 KB Output is correct
31 Correct 120 ms 16784 KB Output is correct
32 Correct 114 ms 16732 KB Output is correct
33 Correct 116 ms 16716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 116 ms 16664 KB Output is correct
5 Correct 117 ms 16724 KB Output is correct
6 Correct 121 ms 16732 KB Output is correct
7 Correct 135 ms 16688 KB Output is correct
8 Correct 126 ms 16732 KB Output is correct
9 Correct 111 ms 16716 KB Output is correct
10 Correct 117 ms 16684 KB Output is correct
11 Correct 121 ms 16692 KB Output is correct
12 Correct 121 ms 16732 KB Output is correct
13 Correct 118 ms 16668 KB Output is correct
14 Correct 143 ms 16716 KB Output is correct
15 Correct 128 ms 16776 KB Output is correct
16 Correct 122 ms 16628 KB Output is correct
17 Correct 134 ms 16688 KB Output is correct
18 Correct 127 ms 16728 KB Output is correct
19 Correct 122 ms 16632 KB Output is correct
20 Correct 126 ms 16728 KB Output is correct
21 Correct 113 ms 16728 KB Output is correct
22 Correct 114 ms 16624 KB Output is correct
23 Correct 125 ms 16708 KB Output is correct
24 Correct 114 ms 16784 KB Output is correct
25 Correct 111 ms 16724 KB Output is correct
26 Correct 111 ms 16640 KB Output is correct
27 Correct 110 ms 16684 KB Output is correct
28 Correct 127 ms 16728 KB Output is correct
29 Correct 112 ms 16716 KB Output is correct
30 Correct 112 ms 16740 KB Output is correct
31 Correct 120 ms 16784 KB Output is correct
32 Correct 114 ms 16732 KB Output is correct
33 Correct 116 ms 16716 KB Output is correct
34 Incorrect 284 ms 1440 KB Output isn't correct
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 116 ms 16664 KB Output is correct
5 Correct 117 ms 16724 KB Output is correct
6 Correct 121 ms 16732 KB Output is correct
7 Correct 135 ms 16688 KB Output is correct
8 Correct 126 ms 16732 KB Output is correct
9 Correct 111 ms 16716 KB Output is correct
10 Correct 117 ms 16684 KB Output is correct
11 Correct 121 ms 16692 KB Output is correct
12 Correct 121 ms 16732 KB Output is correct
13 Correct 118 ms 16668 KB Output is correct
14 Correct 143 ms 16716 KB Output is correct
15 Correct 128 ms 16776 KB Output is correct
16 Correct 122 ms 16628 KB Output is correct
17 Correct 134 ms 16688 KB Output is correct
18 Correct 127 ms 16728 KB Output is correct
19 Correct 122 ms 16632 KB Output is correct
20 Correct 126 ms 16728 KB Output is correct
21 Correct 113 ms 16728 KB Output is correct
22 Correct 114 ms 16624 KB Output is correct
23 Correct 125 ms 16708 KB Output is correct
24 Correct 114 ms 16784 KB Output is correct
25 Correct 111 ms 16724 KB Output is correct
26 Correct 111 ms 16640 KB Output is correct
27 Correct 110 ms 16684 KB Output is correct
28 Correct 127 ms 16728 KB Output is correct
29 Correct 112 ms 16716 KB Output is correct
30 Correct 112 ms 16740 KB Output is correct
31 Correct 120 ms 16784 KB Output is correct
32 Correct 114 ms 16732 KB Output is correct
33 Correct 116 ms 16716 KB Output is correct
34 Incorrect 284 ms 1440 KB Output isn't correct
35 Halted 0 ms 0 KB -