Submission #367118

#TimeUsernameProblemLanguageResultExecution timeMemory
367118Lam_lai_cuoc_doiCoin Collecting (JOI19_ho_t4)C++17
37 / 100
15 ms8448 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const bool typetest = 0; const int N = 1e3 + 5; const ll Inf = 1e17; pair<ll, ll> a[N * 2]; int n; ll dp[N][N]; void Read() { cin >> n; for (int i = 1; i <= n * 2; ++i) cin >> a[i].first >> a[i].second; sort(a + 1, a + n * 2 + 1); } inline void Min(ll &x, ll y) { if (x > y) x = y; } void Solve() { fill_n(&dp[0][0], N * N, Inf); dp[0][0] = 0; for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) { if (i < n) Min(dp[i + 1][j], dp[i][j] + abs(a[i + j + 1].first - i - 1) + abs(a[i + j + 1].second - 1)); if (j < n) Min(dp[i][j + 1], dp[i][j] + abs(a[i + j + 1].first - j - 1) + abs(a[i + j + 1].second - 2)); } cout << dp[n][n]; } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t(1); if (typetest) cin >> t; for (int _ = 1; _ <= t; ++_) { Read(); Solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...