답안 #855732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855732 2023-10-01T17:24:51 Z denniskim Coin Collecting (JOI19_ho_t4) C++17
37 / 100
1000 ms 274432 KB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef __int128 lll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
#define MAX 9223372036854775807LL
#define MIN -9223372036854775807LL
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << fixed; cout.precision(10);
#define sp << " "
#define en << "\n"
#define compress(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end())

ll n;
ll dp[5010][5010];
pll a[5010];

ll dist(ll x1, ll y1, ll x2, ll y2)
{
	return abs(x1 - x2) + abs(y1 - y2);
}

bool comp(pll X, pll Y)
{
	return make_pair(X.se, X.fi) < make_pair(Y.se, Y.fi);
}

int main(void)
{
	fastio
	
	cin >> n;
	
	for(ll i = 1 ; i <= n * 2 ; i++)
		cin >> a[i].fi >> a[i].se;
	
	sort(a + 1, a + 1 + n * 2);
	
	for(ll i = 0 ; i <= n ; i++)
	{
		for(ll j = 0 ; j <= n ; j++)
			dp[i][j] = INF;
	}
	
	dp[0][0] = 0;
	
	for(ll i = 1 ; i <= n * 2 ; i++)
	{
		for(ll j = 0 ; j < i ; j++)
		{
			ll k = i - 1 - j;
			
			if(j + 1 <= n)
				dp[j + 1][k] = min(dp[j + 1][k], dp[j][k] + dist(j + 1, 1, a[i].fi, a[i].se));
			
			if(k + 1 <= n)
				dp[j][k + 1] = min(dp[j][k + 1], dp[j][k] + dist(k + 1, 2, a[i].fi, a[i].se));
		}
	}
	
	cout << dp[n][n];
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 18 ms 48988 KB Output is correct
35 Correct 19 ms 48988 KB Output is correct
36 Correct 21 ms 48980 KB Output is correct
37 Correct 21 ms 48864 KB Output is correct
38 Correct 18 ms 48980 KB Output is correct
39 Correct 17 ms 48984 KB Output is correct
40 Correct 20 ms 48988 KB Output is correct
41 Correct 18 ms 48976 KB Output is correct
42 Correct 19 ms 49004 KB Output is correct
43 Correct 20 ms 48984 KB Output is correct
44 Correct 21 ms 48988 KB Output is correct
45 Correct 18 ms 48896 KB Output is correct
46 Correct 18 ms 48988 KB Output is correct
47 Correct 18 ms 48988 KB Output is correct
48 Correct 18 ms 48988 KB Output is correct
49 Correct 21 ms 49236 KB Output is correct
50 Correct 18 ms 48988 KB Output is correct
51 Correct 18 ms 48984 KB Output is correct
52 Correct 19 ms 48988 KB Output is correct
53 Correct 19 ms 49008 KB Output is correct
54 Correct 20 ms 48840 KB Output is correct
55 Correct 19 ms 48988 KB Output is correct
56 Correct 18 ms 48988 KB Output is correct
57 Correct 18 ms 48844 KB Output is correct
58 Correct 18 ms 48980 KB Output is correct
59 Correct 18 ms 48804 KB Output is correct
60 Correct 18 ms 49028 KB Output is correct
61 Correct 19 ms 48896 KB Output is correct
62 Correct 18 ms 48988 KB Output is correct
63 Correct 19 ms 48796 KB Output is correct
64 Correct 18 ms 48988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 0 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 1 ms 2392 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 0 ms 2396 KB Output is correct
23 Correct 1 ms 2392 KB Output is correct
24 Correct 1 ms 2392 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 0 ms 2396 KB Output is correct
27 Correct 0 ms 2396 KB Output is correct
28 Correct 0 ms 2396 KB Output is correct
29 Correct 0 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 0 ms 2396 KB Output is correct
32 Correct 0 ms 2396 KB Output is correct
33 Correct 0 ms 2396 KB Output is correct
34 Correct 18 ms 48988 KB Output is correct
35 Correct 19 ms 48988 KB Output is correct
36 Correct 21 ms 48980 KB Output is correct
37 Correct 21 ms 48864 KB Output is correct
38 Correct 18 ms 48980 KB Output is correct
39 Correct 17 ms 48984 KB Output is correct
40 Correct 20 ms 48988 KB Output is correct
41 Correct 18 ms 48976 KB Output is correct
42 Correct 19 ms 49004 KB Output is correct
43 Correct 20 ms 48984 KB Output is correct
44 Correct 21 ms 48988 KB Output is correct
45 Correct 18 ms 48896 KB Output is correct
46 Correct 18 ms 48988 KB Output is correct
47 Correct 18 ms 48988 KB Output is correct
48 Correct 18 ms 48988 KB Output is correct
49 Correct 21 ms 49236 KB Output is correct
50 Correct 18 ms 48988 KB Output is correct
51 Correct 18 ms 48984 KB Output is correct
52 Correct 19 ms 48988 KB Output is correct
53 Correct 19 ms 49008 KB Output is correct
54 Correct 20 ms 48840 KB Output is correct
55 Correct 19 ms 48988 KB Output is correct
56 Correct 18 ms 48988 KB Output is correct
57 Correct 18 ms 48844 KB Output is correct
58 Correct 18 ms 48980 KB Output is correct
59 Correct 18 ms 48804 KB Output is correct
60 Correct 18 ms 49028 KB Output is correct
61 Correct 19 ms 48896 KB Output is correct
62 Correct 18 ms 48988 KB Output is correct
63 Correct 19 ms 48796 KB Output is correct
64 Correct 18 ms 48988 KB Output is correct
65 Execution timed out 2303 ms 274432 KB Time limit exceeded
66 Halted 0 ms 0 KB -