Submission #704109

# Submission time Handle Problem Language Result Execution time Memory
704109 2023-03-01T15:23:39 Z 1075508020060209tc Coin Collecting (JOI19_ho_t4) C++14
8 / 100
13 ms 16212 KB
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int n;
pair<int,int>ar[500005];
int dp[2010][1010];

int cst(pair<int,int>pt,int x,int y){
return abs(pt.X-x)+abs(pt.Y-y);
}

signed main(){

cin>>n;
for(int i=1;i<=n+n;i++){
    cin>>ar[i].X>>ar[i].Y;
}

for(int i=0;i<=2000;i++){
    for(int j=0;j<=1000;j++){
        dp[i][j]=1e12;
    }
}

sort(ar+1,ar+n+n+1);

dp[1][0]=cst(ar[1],1,1);
dp[1][1]=cst(ar[1],1,2);
for(int i=1;i<=n+n;i++){
    for(int j=0;j<=n;j++){
        dp[i+1][j]=min(dp[i+1][j],dp[i][j]+cst(ar[i+1],i+1-j,1));
        dp[i+1][j+1]=min(dp[i+1][j+1],dp[i][j]+cst(ar[i+1],j+1,2));
    }
}
cout<<dp[n+n][n];

}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16080 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 7 ms 16084 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16048 KB Output is correct
8 Correct 7 ms 16084 KB Output is correct
9 Correct 7 ms 16056 KB Output is correct
10 Correct 7 ms 16084 KB Output is correct
11 Correct 7 ms 16084 KB Output is correct
12 Correct 7 ms 16084 KB Output is correct
13 Correct 6 ms 16132 KB Output is correct
14 Correct 6 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 7 ms 16084 KB Output is correct
17 Correct 6 ms 16084 KB Output is correct
18 Correct 7 ms 16084 KB Output is correct
19 Correct 6 ms 16084 KB Output is correct
20 Correct 7 ms 16048 KB Output is correct
21 Correct 7 ms 16060 KB Output is correct
22 Correct 7 ms 16084 KB Output is correct
23 Correct 6 ms 16048 KB Output is correct
24 Correct 7 ms 16052 KB Output is correct
25 Correct 8 ms 16084 KB Output is correct
26 Correct 7 ms 16044 KB Output is correct
27 Correct 7 ms 16052 KB Output is correct
28 Correct 7 ms 16084 KB Output is correct
29 Correct 7 ms 16084 KB Output is correct
30 Correct 7 ms 16084 KB Output is correct
31 Correct 7 ms 16084 KB Output is correct
32 Correct 7 ms 16084 KB Output is correct
33 Correct 7 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16080 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 7 ms 16084 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16048 KB Output is correct
8 Correct 7 ms 16084 KB Output is correct
9 Correct 7 ms 16056 KB Output is correct
10 Correct 7 ms 16084 KB Output is correct
11 Correct 7 ms 16084 KB Output is correct
12 Correct 7 ms 16084 KB Output is correct
13 Correct 6 ms 16132 KB Output is correct
14 Correct 6 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 7 ms 16084 KB Output is correct
17 Correct 6 ms 16084 KB Output is correct
18 Correct 7 ms 16084 KB Output is correct
19 Correct 6 ms 16084 KB Output is correct
20 Correct 7 ms 16048 KB Output is correct
21 Correct 7 ms 16060 KB Output is correct
22 Correct 7 ms 16084 KB Output is correct
23 Correct 6 ms 16048 KB Output is correct
24 Correct 7 ms 16052 KB Output is correct
25 Correct 8 ms 16084 KB Output is correct
26 Correct 7 ms 16044 KB Output is correct
27 Correct 7 ms 16052 KB Output is correct
28 Correct 7 ms 16084 KB Output is correct
29 Correct 7 ms 16084 KB Output is correct
30 Correct 7 ms 16084 KB Output is correct
31 Correct 7 ms 16084 KB Output is correct
32 Correct 7 ms 16084 KB Output is correct
33 Correct 7 ms 16084 KB Output is correct
34 Correct 12 ms 16084 KB Output is correct
35 Incorrect 13 ms 16212 KB Output isn't correct
36 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 7 ms 16080 KB Output is correct
4 Correct 7 ms 16084 KB Output is correct
5 Correct 7 ms 16084 KB Output is correct
6 Correct 7 ms 16072 KB Output is correct
7 Correct 7 ms 16048 KB Output is correct
8 Correct 7 ms 16084 KB Output is correct
9 Correct 7 ms 16056 KB Output is correct
10 Correct 7 ms 16084 KB Output is correct
11 Correct 7 ms 16084 KB Output is correct
12 Correct 7 ms 16084 KB Output is correct
13 Correct 6 ms 16132 KB Output is correct
14 Correct 6 ms 16084 KB Output is correct
15 Correct 7 ms 16084 KB Output is correct
16 Correct 7 ms 16084 KB Output is correct
17 Correct 6 ms 16084 KB Output is correct
18 Correct 7 ms 16084 KB Output is correct
19 Correct 6 ms 16084 KB Output is correct
20 Correct 7 ms 16048 KB Output is correct
21 Correct 7 ms 16060 KB Output is correct
22 Correct 7 ms 16084 KB Output is correct
23 Correct 6 ms 16048 KB Output is correct
24 Correct 7 ms 16052 KB Output is correct
25 Correct 8 ms 16084 KB Output is correct
26 Correct 7 ms 16044 KB Output is correct
27 Correct 7 ms 16052 KB Output is correct
28 Correct 7 ms 16084 KB Output is correct
29 Correct 7 ms 16084 KB Output is correct
30 Correct 7 ms 16084 KB Output is correct
31 Correct 7 ms 16084 KB Output is correct
32 Correct 7 ms 16084 KB Output is correct
33 Correct 7 ms 16084 KB Output is correct
34 Correct 12 ms 16084 KB Output is correct
35 Incorrect 13 ms 16212 KB Output isn't correct
36 Halted 0 ms 0 KB -