Submission #101196

#TimeUsernameProblemLanguageResultExecution timeMemory
101196Pro_ktmrCoin Collecting (JOI19_ho_t4)C++14
0 / 100
20 ms16768 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...