Submission #532116

#TimeUsernameProblemLanguageResultExecution timeMemory
532116rk42745417Coin Collecting (JOI19_ho_t4)C++17
37 / 100
1075 ms5504 KiB
#include <bits/stdc++.h> using namespace std; #define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0); using ll = int64_t; using ull = uint64_t; using uint = uint32_t; using ld = long double; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const ll LINF = ll(4e15) + ll(2e15); const double EPS = 1e-9; static int LamyIsCute = []() { EmiliaMyWife return 48763; }(); #pragma GCC optimize("Ofast,no-stack-protector") #pragma GCC target("sse,sse2,ssse3,sse4,tune=native") const int N = 1e5 + 25; ll dp[2][N * 2]; pair<ll, ll> arr[N * 2]; signed main() { int n; cin >> n; for(int i = 0; i < n * 2; i++) cin >> arr[i].first >> arr[i].second; sort(arr, arr + n * 2); int prv = 0, nxt = 1; dp[prv][0] = 0; for(int s = 0; s < n * 2; s++) { for(int i = 0; i <= s + 1; i++) dp[nxt][i] = LINF; for(int i = max(0, s - n); i <= min(n, s); i++) { int j = s - i; if(i < n) dp[nxt][i + 1] = min(dp[nxt][i + 1], dp[prv][i] + abs(arr[s].first - (i + 1)) + abs(arr[s].second - 2)); if(j < n) dp[nxt][i] = min(dp[nxt][i], dp[prv][i] + abs(arr[s].first - (j + 1)) + abs(arr[s].second - 1)); } swap(nxt, prv); } cout << dp[prv][n] << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...