답안 #1116028

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116028 2024-11-21T07:59:51 Z Dan4Life Coin Collecting (JOI19_ho_t4) C++17
0 / 100
44 ms 8520 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (int)1e5+2;
const int LINF = (int)2e18;
int n, x[N], y[N];
array<int,2> a[N];
int dp[N];
int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n; n*=2;
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    for(int i = 1; i <= n; i+=2)
        a[i] = {i/2+1,1}, a[i+1] = {i/2+1,2};
    dp[0] = 0;
    for(int mask = 1; mask < (1<<n); mask++){
        int num = __builtin_popcount(mask);
        dp[mask] = LINF;
        for(int i = 0; i < n; i++){
            if(mask>>i&1){
                dp[mask] = min(dp[mask], dp[mask^(1<<i)]
                +abs(a[num][0]-x[i])+abs(a[num][1]-y[i]));
            }
        }
    }
    cout << dp[(1<<n)-1] << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Runtime error 44 ms 8520 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Runtime error 44 ms 8520 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2552 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Runtime error 44 ms 8520 KB Execution killed with signal 11
5 Halted 0 ms 0 KB -