Submission #1116042

# Submission time Handle Problem Language Result Execution time Memory
1116042 2024-11-21T08:12:21 Z Dan4Life Coin Collecting (JOI19_ho_t4) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = (int)2e3+10;
const int LINF = (int)2e18;
int n, dp[N][N];
array<int,2> a[2][N], loc[N];

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n; n*=2;
    for(int i = 1; i <= n; i++) 
        cin >> loc[i][0] >> loc[i][1];
    sort(loc,loc+n);
    for(int i = 1; i <= n/2; i++)
        a[0][i] = {i,1}, a[1][i] = {i,2};
    for(int i = 0; i <= n/2; i++)
        for(int j = 0; j <= n/2; j++)
            dp[i][j]=LINF;
    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(i-loc[i+j][0])+abs(1-loc[i+j][1]));
            if(j) dp[i][j] = min(dp[i][j], dp[i][j-1]
            +abs(i-loc[i+j][0])+abs(2-loc[i+j][1]));
        }
    }
    cout << dp[n/2][n/2] << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -