Submission #169088

#TimeUsernameProblemLanguageResultExecution timeMemory
169088srvltCoin Collecting (JOI19_ho_t4)C++14
37 / 100
137 ms55044 KiB
//#pragma GCC target ("avx2,sse2") //#pragma GCC optimization ("Ofast") //#pragma GCC optimization ("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; #define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define db double #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define fi first #define se second #define mp make_pair #define up_b upper_bound #define low_b lower_bound #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #define endl "\n" #define left fsdsdfoisf #define sum dpsdfioppsf #define assign xcvjlkdjfio #define trie fksdfkjkfnjuiv #define next sidlfjsfkl #define merge sdfksdkfsldf #define int long long using namespace std; void dout() { cerr << endl; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << H << ' '; dout(T...); } //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); typedef pair <int, int> pii; const int N = 2007, inf = 1e18; int n, dp[N][N]; vector <pii> v; void solve(int tc) { // check for (int i = 0; i < n; j++) cin >> n; n *= 2; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; v.pb({x, y}); } sort(all(v)); for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; j++) { dp[i][j] = inf; if (j < i) { dp[i][j] = min(dp[i][j], dp[i - 1][j] + abs(2 - v[i - 1].se) + abs(i - j - v[i - 1].fi)); } if (j > 0) { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + abs(1 - v[i - 1].se) + abs(j - v[i - 1].fi)); } } } cout << dp[n][n / 2]; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); // freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout); int tc = 1; // cin >> tc; for (int i = 0; i < tc; i++) { solve(i); // cleanup(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...