Submission #1156952

#TimeUsernameProblemLanguageResultExecution timeMemory
1156952PacybwoahCoin Collecting (JOI19_ho_t4)C++20
37 / 100
174 ms339968 KiB
#include<iostream> #include<algorithm> #include<utility> #include<vector> #include<cmath> using namespace std; typedef long long ll; const ll inf = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; vector<pair<ll, ll>> vec(2 * n); for(int i = 0; i < 2 * n; i++) cin >> vec[i].first >> vec[i].second; sort(vec.begin(), vec.end()); vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, inf)); dp[0][0] = 0; auto calc = [&](pair<ll, ll> a, pair<ll, ll> b){ return llabs(a.first - b.first) + llabs(a.second - b.second); }; for(int i = 0; i <= n; i++){ for(int j = 0; j <= n; j++){ if(i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + calc(vec[i + j - 1], make_pair(i, 1))); if(j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + calc(vec[i + j - 1], make_pair(j, 2))); } } cout << dp[n][n] << "\n"; } // g++ -std=c++17 -Wall -Wextra -Wshadow -fsanitize=undefined -fsanitize=address -o run pD.cpp
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...