Submission #416082

#TimeUsernameProblemLanguageResultExecution timeMemory
416082meatrowCoin Collecting (JOI19_ho_t4)C++17
37 / 100
74 ms24228 KiB
// #pragma GCC target ("avx2") // #pragma GCC optimization ("O3") #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int MOD = 1e9 + 7; ll binpow(ll a, ll p, int mod = MOD) { ll res = 1; while (p) { if (p & 1) { (res *= a) %= mod; } p >>= 1; (a *= a) %= mod; } return res; } ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } const int N = 1001; ll dp[N][N]; void solve() { int n; cin >> n; n *= 2; vector<pair<ll, ll>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; } sort(a.begin(), a.end()); for (int i = 0; i <= n / 2; i++) { fill(dp[i], dp[i] + N, 1e18); } dp[0][0] = 0; for (int i = 0; i <= n / 2; i++) { for (int j = 0; j <= n / 2; j++) { if (i) { dp[i][j] = min(dp[i][j], dp[i - 1][j] + abs(a[i + j - 1].first - i) + abs(a[i + j - 1].second - 1)); } if (j) { dp[i][j] = min(dp[i][j], dp[i][j - 1] + abs(a[i + j - 1].first - j) + abs(a[i + j - 1].second - 2)); } } } cout << dp[n / 2][n / 2] << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; // cin >> T; for (int tc = 1; tc <= T; tc++) { // cout << "Case #" << tc << ": "; solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...