Submission #416079

#TimeUsernameProblemLanguageResultExecution timeMemory
416079meatrowCoin Collecting (JOI19_ho_t4)C++17
0 / 100
2 ms480 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<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first >> a[i].second; fill(dp[i + 1], dp[i + 1] + N, 1e18); } sort(a.begin(), a.end()); for (int i = 1; i <= n; i++) { for (int j = 0; j <= i; 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...