#include <bits/stdc++.h>
#define int long long
//#define double long double
#define Nanase_Kurumi_aka_menhera_chan_is_mine ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pi pair<double,int>
#define ALL(i) i.begin(),i.end()
#define gcd(i,j) __gcd(i,j)
#define fi first
#define se second
#define eps 0.00000001
#define ist insert
#define DNE nullptr
//#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
//#pragma GCC optimize("O2")
int max(int x,int y){return x>=y?x:y;}
int min(int x,int y){return x>=y?y:x;}
using namespace std;
typedef int ll;
const int N=2005;
const int M=1000005;
const int MOD=1000000007;//998244353;
const int INF=1000000000000000000;//2147483647;
int n,ans;
pi p[N];
int dp[2*N][2*N];
inline void sol(){
cin >>n;
for (int i=1;i<=2*n;i++)
cin >>p[i].fi>>p[i].se;
sort(p+1,p+2*n+1);
for (int i=1;i<=2*n;i++){
dp[0][i]=dp[0][i-1]+abs(p[i].fi-i)+abs(2-p[i].se);
dp[i][0]=dp[i-1][0]+abs(p[i].fi-i)+abs(1-p[i].se);
for (int j=1;j<i;j++)
dp[j][i-j]=min(dp[j-1][i-j]+abs(p[i].fi-j)+abs(1-p[i].se),dp[j][i-j-1]+abs(p[i].fi-(i-j))+abs(2-p[i].se));
}
cout <<dp[n][n];
}
signed main(){
Nanase_Kurumi_aka_menhera_chan_is_mine
int _=1;
//cin >>_;
while (_--) sol();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
23 ms |
24012 KB |
Output is correct |
35 |
Correct |
23 ms |
24104 KB |
Output is correct |
36 |
Correct |
33 ms |
24068 KB |
Output is correct |
37 |
Correct |
33 ms |
24072 KB |
Output is correct |
38 |
Correct |
25 ms |
24044 KB |
Output is correct |
39 |
Correct |
24 ms |
24068 KB |
Output is correct |
40 |
Correct |
30 ms |
24036 KB |
Output is correct |
41 |
Correct |
22 ms |
24012 KB |
Output is correct |
42 |
Correct |
23 ms |
24012 KB |
Output is correct |
43 |
Correct |
25 ms |
24028 KB |
Output is correct |
44 |
Correct |
22 ms |
24004 KB |
Output is correct |
45 |
Correct |
26 ms |
24028 KB |
Output is correct |
46 |
Correct |
23 ms |
24012 KB |
Output is correct |
47 |
Correct |
25 ms |
24016 KB |
Output is correct |
48 |
Correct |
24 ms |
24140 KB |
Output is correct |
49 |
Correct |
24 ms |
24036 KB |
Output is correct |
50 |
Correct |
23 ms |
24104 KB |
Output is correct |
51 |
Correct |
32 ms |
24104 KB |
Output is correct |
52 |
Correct |
24 ms |
24052 KB |
Output is correct |
53 |
Correct |
26 ms |
24140 KB |
Output is correct |
54 |
Correct |
33 ms |
24004 KB |
Output is correct |
55 |
Correct |
23 ms |
23988 KB |
Output is correct |
56 |
Correct |
23 ms |
24072 KB |
Output is correct |
57 |
Correct |
24 ms |
24004 KB |
Output is correct |
58 |
Correct |
25 ms |
24024 KB |
Output is correct |
59 |
Correct |
24 ms |
24012 KB |
Output is correct |
60 |
Correct |
26 ms |
24012 KB |
Output is correct |
61 |
Correct |
26 ms |
24028 KB |
Output is correct |
62 |
Correct |
28 ms |
24040 KB |
Output is correct |
63 |
Correct |
24 ms |
24072 KB |
Output is correct |
64 |
Correct |
24 ms |
24004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
23 ms |
24012 KB |
Output is correct |
35 |
Correct |
23 ms |
24104 KB |
Output is correct |
36 |
Correct |
33 ms |
24068 KB |
Output is correct |
37 |
Correct |
33 ms |
24072 KB |
Output is correct |
38 |
Correct |
25 ms |
24044 KB |
Output is correct |
39 |
Correct |
24 ms |
24068 KB |
Output is correct |
40 |
Correct |
30 ms |
24036 KB |
Output is correct |
41 |
Correct |
22 ms |
24012 KB |
Output is correct |
42 |
Correct |
23 ms |
24012 KB |
Output is correct |
43 |
Correct |
25 ms |
24028 KB |
Output is correct |
44 |
Correct |
22 ms |
24004 KB |
Output is correct |
45 |
Correct |
26 ms |
24028 KB |
Output is correct |
46 |
Correct |
23 ms |
24012 KB |
Output is correct |
47 |
Correct |
25 ms |
24016 KB |
Output is correct |
48 |
Correct |
24 ms |
24140 KB |
Output is correct |
49 |
Correct |
24 ms |
24036 KB |
Output is correct |
50 |
Correct |
23 ms |
24104 KB |
Output is correct |
51 |
Correct |
32 ms |
24104 KB |
Output is correct |
52 |
Correct |
24 ms |
24052 KB |
Output is correct |
53 |
Correct |
26 ms |
24140 KB |
Output is correct |
54 |
Correct |
33 ms |
24004 KB |
Output is correct |
55 |
Correct |
23 ms |
23988 KB |
Output is correct |
56 |
Correct |
23 ms |
24072 KB |
Output is correct |
57 |
Correct |
24 ms |
24004 KB |
Output is correct |
58 |
Correct |
25 ms |
24024 KB |
Output is correct |
59 |
Correct |
24 ms |
24012 KB |
Output is correct |
60 |
Correct |
26 ms |
24012 KB |
Output is correct |
61 |
Correct |
26 ms |
24028 KB |
Output is correct |
62 |
Correct |
28 ms |
24040 KB |
Output is correct |
63 |
Correct |
24 ms |
24072 KB |
Output is correct |
64 |
Correct |
24 ms |
24004 KB |
Output is correct |
65 |
Incorrect |
1 ms |
460 KB |
Output isn't correct |
66 |
Halted |
0 ms |
0 KB |
- |