Submission #704111

# Submission time Handle Problem Language Result Execution time Memory
704111 2023-03-01T15:25:07 Z 1075508020060209tc Coin Collecting (JOI19_ho_t4) C++14
37 / 100
953 ms 50032 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]=1e16;
    }
}

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 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 6 ms 16044 KB Output is correct
4 Correct 9 ms 16100 KB Output is correct
5 Correct 7 ms 16020 KB Output is correct
6 Correct 7 ms 16092 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16084 KB Output is correct
9 Correct 6 ms 16084 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 16072 KB Output is correct
13 Correct 7 ms 16116 KB Output is correct
14 Correct 6 ms 16024 KB Output is correct
15 Correct 7 ms 16040 KB Output is correct
16 Correct 7 ms 16112 KB Output is correct
17 Correct 6 ms 16084 KB Output is correct
18 Correct 6 ms 16084 KB Output is correct
19 Correct 6 ms 16084 KB Output is correct
20 Correct 9 ms 16084 KB Output is correct
21 Correct 7 ms 16044 KB Output is correct
22 Correct 7 ms 16016 KB Output is correct
23 Correct 7 ms 16084 KB Output is correct
24 Correct 6 ms 16084 KB Output is correct
25 Correct 7 ms 16084 KB Output is correct
26 Correct 7 ms 16044 KB Output is correct
27 Correct 7 ms 16128 KB Output is correct
28 Correct 8 ms 16140 KB Output is correct
29 Correct 6 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 8 ms 16084 KB Output is correct
33 Correct 6 ms 16128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 6 ms 16044 KB Output is correct
4 Correct 9 ms 16100 KB Output is correct
5 Correct 7 ms 16020 KB Output is correct
6 Correct 7 ms 16092 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16084 KB Output is correct
9 Correct 6 ms 16084 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 16072 KB Output is correct
13 Correct 7 ms 16116 KB Output is correct
14 Correct 6 ms 16024 KB Output is correct
15 Correct 7 ms 16040 KB Output is correct
16 Correct 7 ms 16112 KB Output is correct
17 Correct 6 ms 16084 KB Output is correct
18 Correct 6 ms 16084 KB Output is correct
19 Correct 6 ms 16084 KB Output is correct
20 Correct 9 ms 16084 KB Output is correct
21 Correct 7 ms 16044 KB Output is correct
22 Correct 7 ms 16016 KB Output is correct
23 Correct 7 ms 16084 KB Output is correct
24 Correct 6 ms 16084 KB Output is correct
25 Correct 7 ms 16084 KB Output is correct
26 Correct 7 ms 16044 KB Output is correct
27 Correct 7 ms 16128 KB Output is correct
28 Correct 8 ms 16140 KB Output is correct
29 Correct 6 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 8 ms 16084 KB Output is correct
33 Correct 6 ms 16128 KB Output is correct
34 Correct 12 ms 16084 KB Output is correct
35 Correct 14 ms 16156 KB Output is correct
36 Correct 15 ms 16188 KB Output is correct
37 Correct 12 ms 16084 KB Output is correct
38 Correct 18 ms 16184 KB Output is correct
39 Correct 18 ms 16088 KB Output is correct
40 Correct 13 ms 16096 KB Output is correct
41 Correct 13 ms 16192 KB Output is correct
42 Correct 12 ms 16084 KB Output is correct
43 Correct 13 ms 16192 KB Output is correct
44 Correct 13 ms 16184 KB Output is correct
45 Correct 13 ms 16212 KB Output is correct
46 Correct 13 ms 16184 KB Output is correct
47 Correct 16 ms 16084 KB Output is correct
48 Correct 13 ms 16084 KB Output is correct
49 Correct 13 ms 16084 KB Output is correct
50 Correct 13 ms 16084 KB Output is correct
51 Correct 13 ms 16176 KB Output is correct
52 Correct 13 ms 16180 KB Output is correct
53 Correct 13 ms 16092 KB Output is correct
54 Correct 13 ms 16192 KB Output is correct
55 Correct 16 ms 16100 KB Output is correct
56 Correct 13 ms 16100 KB Output is correct
57 Correct 12 ms 16188 KB Output is correct
58 Correct 13 ms 16084 KB Output is correct
59 Correct 13 ms 16192 KB Output is correct
60 Correct 13 ms 16084 KB Output is correct
61 Correct 13 ms 16084 KB Output is correct
62 Correct 14 ms 16192 KB Output is correct
63 Correct 21 ms 16176 KB Output is correct
64 Correct 12 ms 16084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16084 KB Output is correct
2 Correct 7 ms 16084 KB Output is correct
3 Correct 6 ms 16044 KB Output is correct
4 Correct 9 ms 16100 KB Output is correct
5 Correct 7 ms 16020 KB Output is correct
6 Correct 7 ms 16092 KB Output is correct
7 Correct 7 ms 16084 KB Output is correct
8 Correct 7 ms 16084 KB Output is correct
9 Correct 6 ms 16084 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 16072 KB Output is correct
13 Correct 7 ms 16116 KB Output is correct
14 Correct 6 ms 16024 KB Output is correct
15 Correct 7 ms 16040 KB Output is correct
16 Correct 7 ms 16112 KB Output is correct
17 Correct 6 ms 16084 KB Output is correct
18 Correct 6 ms 16084 KB Output is correct
19 Correct 6 ms 16084 KB Output is correct
20 Correct 9 ms 16084 KB Output is correct
21 Correct 7 ms 16044 KB Output is correct
22 Correct 7 ms 16016 KB Output is correct
23 Correct 7 ms 16084 KB Output is correct
24 Correct 6 ms 16084 KB Output is correct
25 Correct 7 ms 16084 KB Output is correct
26 Correct 7 ms 16044 KB Output is correct
27 Correct 7 ms 16128 KB Output is correct
28 Correct 8 ms 16140 KB Output is correct
29 Correct 6 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 8 ms 16084 KB Output is correct
33 Correct 6 ms 16128 KB Output is correct
34 Correct 12 ms 16084 KB Output is correct
35 Correct 14 ms 16156 KB Output is correct
36 Correct 15 ms 16188 KB Output is correct
37 Correct 12 ms 16084 KB Output is correct
38 Correct 18 ms 16184 KB Output is correct
39 Correct 18 ms 16088 KB Output is correct
40 Correct 13 ms 16096 KB Output is correct
41 Correct 13 ms 16192 KB Output is correct
42 Correct 12 ms 16084 KB Output is correct
43 Correct 13 ms 16192 KB Output is correct
44 Correct 13 ms 16184 KB Output is correct
45 Correct 13 ms 16212 KB Output is correct
46 Correct 13 ms 16184 KB Output is correct
47 Correct 16 ms 16084 KB Output is correct
48 Correct 13 ms 16084 KB Output is correct
49 Correct 13 ms 16084 KB Output is correct
50 Correct 13 ms 16084 KB Output is correct
51 Correct 13 ms 16176 KB Output is correct
52 Correct 13 ms 16180 KB Output is correct
53 Correct 13 ms 16092 KB Output is correct
54 Correct 13 ms 16192 KB Output is correct
55 Correct 16 ms 16100 KB Output is correct
56 Correct 13 ms 16100 KB Output is correct
57 Correct 12 ms 16188 KB Output is correct
58 Correct 13 ms 16084 KB Output is correct
59 Correct 13 ms 16192 KB Output is correct
60 Correct 13 ms 16084 KB Output is correct
61 Correct 13 ms 16084 KB Output is correct
62 Correct 14 ms 16192 KB Output is correct
63 Correct 21 ms 16176 KB Output is correct
64 Correct 12 ms 16084 KB Output is correct
65 Runtime error 953 ms 50032 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -