Submission #416083

#TimeUsernameProblemLanguageResultExecution timeMemory
416083meatrowCoin Collecting (JOI19_ho_t4)C++17
8 / 100
13 ms16468 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 = 1005; 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; fill(dp[i], dp[i] + N, 1e18); } fill(dp[n], dp[n] + N, 1e18); sort(a.begin(), a.end()); dp[0][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 0; j <= min(i, n / 2); j++) { if (j) { dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + abs(a[i - 1].first - j) + abs(a[i - 1].second - 1)); } dp[i][j] = min(dp[i][j], dp[i - 1][j] + abs(a[i - 1].first - (i - j)) + abs(a[i - 1].second - 2)); } } cout << dp[n][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...