# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1145280 | SmuggingSpun | Coin Collecting (JOI19_ho_t4) | C++20 | 83 ms | 8524 KiB |
#include<bits/stdc++.h>
#define taskname "D"
using namespace std;
typedef long long ll;
const ll INF = 1e18;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
int n;
namespace sub1{
void solve(){
vector<pair<int, int>>a(n << 1);
for(auto& [x, y] : a){
cin >> x >> y;
}
vector<ll>dp(1 << (n << 1), INF);
dp[0] = 0;
for(int mask = 1; mask < (1 << (n << 1)); mask++){
int cnt = __builtin_popcount(mask);
for(int i = 0; i < (n << 1); i++){
if(1 << i & mask){
if(cnt > n){
minimize(dp[mask], dp[mask ^ (1 << i)] + abs(a[i].first - cnt + n) + abs(a[i].second - 2));
}
else{
minimize(dp[mask], dp[mask ^ (1 << i)] + abs(a[i].first - cnt) + abs(a[i].second - 1));
}
}
}
}
cout << dp.back();
}
}
namespace sub23{
void solve(){
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n;
if(n <= 10){
sub1::solve();
}
else{
sub23::solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |