#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define MP(a,b) make_pair(a,b)
#define int long long
int N;
vector<pair<int,int> > coin;
int dp[20][1<<20];
int solve(int now, int state){
if(now == 2*N) return 0;
if(dp[now][state] != -1) return dp[now][state];
int re = INT_MAX;
for(int i=0; i<2*N; i++){
if((state>>i)%2 == 0){
int y = 1;
if(i >= N) y = 2;
int x = i % N + 1;
re = min(re, abs(coin[now].first-x)+abs(coin[now].second-y)+solve(now+1, state+(1<<i)));
}
}
return dp[now][state] = re;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
if(N > 10) return -1;
for(int i=0; i<N*2; i++){
int a,b;
cin >> a >> b;
coin.push_back(MP(a,b));
for(int j=0; j<(1<<20); j++) dp[i][j] = -1;
}
cout << solve(0,0) << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
20 ms |
16768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
20 ms |
16768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16768 KB |
Output is correct |
2 |
Incorrect |
20 ms |
16768 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |