답안 #670377

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
670377 2022-12-08T19:42:17 Z dozer Coin Collecting (JOI19_ho_t4) C++14
37 / 100
127 ms 152500 KB
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define endl "\n"
#define sp " "
#define N 3005
#define int long long

int dp[N][N];
vector<pii> p;
int n;
const int INF = 1e18 + 7;

int f(int i, int j)
{
	int curr = i + j + 1;
	if (curr > 2 * n) return 0;
	if (dp[i][j] != -1) return dp[i][j];
	int x = p[curr - 1].st;
	int  y = p[curr - 1].nd;
	int t1 = INF, t2 = INF;
	if (i != n) t1 = f(i + 1, j) + abs(x - (i + 1)) + abs(y - 1);
	if (j != n) t2 = f(i, j + 1) + abs(x - (j + 1)) + abs(y - 2);
	return dp[i][j] = min(t1, t2);
}

int32_t main()
{
	fastio();

	memset(dp, -1, sizeof(dp));
	cin>>n;
	for (int i = 1; i <= 2 * n; i++)
	{
		int x, y;
		cin>>x>>y;
		p.pb({x, y});
	}

	sort(p.begin(), p.end());
	cout<<f(0, 0)<<endl;

	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 70860 KB Output is correct
2 Correct 27 ms 71004 KB Output is correct
3 Correct 27 ms 71000 KB Output is correct
4 Correct 27 ms 70908 KB Output is correct
5 Correct 26 ms 70880 KB Output is correct
6 Correct 31 ms 70956 KB Output is correct
7 Correct 30 ms 70984 KB Output is correct
8 Correct 30 ms 70992 KB Output is correct
9 Correct 31 ms 70924 KB Output is correct
10 Correct 26 ms 70984 KB Output is correct
11 Correct 29 ms 70984 KB Output is correct
12 Correct 26 ms 70892 KB Output is correct
13 Correct 27 ms 70996 KB Output is correct
14 Correct 26 ms 70996 KB Output is correct
15 Correct 27 ms 70980 KB Output is correct
16 Correct 27 ms 70880 KB Output is correct
17 Correct 27 ms 70972 KB Output is correct
18 Correct 29 ms 70940 KB Output is correct
19 Correct 27 ms 70996 KB Output is correct
20 Correct 27 ms 70916 KB Output is correct
21 Correct 27 ms 70992 KB Output is correct
22 Correct 28 ms 70992 KB Output is correct
23 Correct 27 ms 70936 KB Output is correct
24 Correct 27 ms 70996 KB Output is correct
25 Correct 31 ms 70924 KB Output is correct
26 Correct 27 ms 70988 KB Output is correct
27 Correct 25 ms 70904 KB Output is correct
28 Correct 26 ms 70984 KB Output is correct
29 Correct 28 ms 70984 KB Output is correct
30 Correct 27 ms 70992 KB Output is correct
31 Correct 28 ms 70892 KB Output is correct
32 Correct 27 ms 70996 KB Output is correct
33 Correct 27 ms 70992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 70860 KB Output is correct
2 Correct 27 ms 71004 KB Output is correct
3 Correct 27 ms 71000 KB Output is correct
4 Correct 27 ms 70908 KB Output is correct
5 Correct 26 ms 70880 KB Output is correct
6 Correct 31 ms 70956 KB Output is correct
7 Correct 30 ms 70984 KB Output is correct
8 Correct 30 ms 70992 KB Output is correct
9 Correct 31 ms 70924 KB Output is correct
10 Correct 26 ms 70984 KB Output is correct
11 Correct 29 ms 70984 KB Output is correct
12 Correct 26 ms 70892 KB Output is correct
13 Correct 27 ms 70996 KB Output is correct
14 Correct 26 ms 70996 KB Output is correct
15 Correct 27 ms 70980 KB Output is correct
16 Correct 27 ms 70880 KB Output is correct
17 Correct 27 ms 70972 KB Output is correct
18 Correct 29 ms 70940 KB Output is correct
19 Correct 27 ms 70996 KB Output is correct
20 Correct 27 ms 70916 KB Output is correct
21 Correct 27 ms 70992 KB Output is correct
22 Correct 28 ms 70992 KB Output is correct
23 Correct 27 ms 70936 KB Output is correct
24 Correct 27 ms 70996 KB Output is correct
25 Correct 31 ms 70924 KB Output is correct
26 Correct 27 ms 70988 KB Output is correct
27 Correct 25 ms 70904 KB Output is correct
28 Correct 26 ms 70984 KB Output is correct
29 Correct 28 ms 70984 KB Output is correct
30 Correct 27 ms 70992 KB Output is correct
31 Correct 28 ms 70892 KB Output is correct
32 Correct 27 ms 70996 KB Output is correct
33 Correct 27 ms 70992 KB Output is correct
34 Correct 41 ms 71108 KB Output is correct
35 Correct 40 ms 71252 KB Output is correct
36 Correct 38 ms 71148 KB Output is correct
37 Correct 39 ms 71184 KB Output is correct
38 Correct 38 ms 71228 KB Output is correct
39 Correct 38 ms 71224 KB Output is correct
40 Correct 38 ms 71116 KB Output is correct
41 Correct 38 ms 71236 KB Output is correct
42 Correct 38 ms 71116 KB Output is correct
43 Correct 41 ms 71156 KB Output is correct
44 Correct 39 ms 71144 KB Output is correct
45 Correct 38 ms 71128 KB Output is correct
46 Correct 38 ms 71160 KB Output is correct
47 Correct 41 ms 71128 KB Output is correct
48 Correct 39 ms 71212 KB Output is correct
49 Correct 40 ms 71128 KB Output is correct
50 Correct 38 ms 71252 KB Output is correct
51 Correct 39 ms 71148 KB Output is correct
52 Correct 39 ms 71252 KB Output is correct
53 Correct 40 ms 71196 KB Output is correct
54 Correct 38 ms 71116 KB Output is correct
55 Correct 39 ms 71244 KB Output is correct
56 Correct 38 ms 71252 KB Output is correct
57 Correct 39 ms 71128 KB Output is correct
58 Correct 43 ms 71224 KB Output is correct
59 Correct 40 ms 71244 KB Output is correct
60 Correct 38 ms 71176 KB Output is correct
61 Correct 44 ms 71124 KB Output is correct
62 Correct 39 ms 71232 KB Output is correct
63 Correct 38 ms 71188 KB Output is correct
64 Correct 39 ms 71240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 70860 KB Output is correct
2 Correct 27 ms 71004 KB Output is correct
3 Correct 27 ms 71000 KB Output is correct
4 Correct 27 ms 70908 KB Output is correct
5 Correct 26 ms 70880 KB Output is correct
6 Correct 31 ms 70956 KB Output is correct
7 Correct 30 ms 70984 KB Output is correct
8 Correct 30 ms 70992 KB Output is correct
9 Correct 31 ms 70924 KB Output is correct
10 Correct 26 ms 70984 KB Output is correct
11 Correct 29 ms 70984 KB Output is correct
12 Correct 26 ms 70892 KB Output is correct
13 Correct 27 ms 70996 KB Output is correct
14 Correct 26 ms 70996 KB Output is correct
15 Correct 27 ms 70980 KB Output is correct
16 Correct 27 ms 70880 KB Output is correct
17 Correct 27 ms 70972 KB Output is correct
18 Correct 29 ms 70940 KB Output is correct
19 Correct 27 ms 70996 KB Output is correct
20 Correct 27 ms 70916 KB Output is correct
21 Correct 27 ms 70992 KB Output is correct
22 Correct 28 ms 70992 KB Output is correct
23 Correct 27 ms 70936 KB Output is correct
24 Correct 27 ms 70996 KB Output is correct
25 Correct 31 ms 70924 KB Output is correct
26 Correct 27 ms 70988 KB Output is correct
27 Correct 25 ms 70904 KB Output is correct
28 Correct 26 ms 70984 KB Output is correct
29 Correct 28 ms 70984 KB Output is correct
30 Correct 27 ms 70992 KB Output is correct
31 Correct 28 ms 70892 KB Output is correct
32 Correct 27 ms 70996 KB Output is correct
33 Correct 27 ms 70992 KB Output is correct
34 Correct 41 ms 71108 KB Output is correct
35 Correct 40 ms 71252 KB Output is correct
36 Correct 38 ms 71148 KB Output is correct
37 Correct 39 ms 71184 KB Output is correct
38 Correct 38 ms 71228 KB Output is correct
39 Correct 38 ms 71224 KB Output is correct
40 Correct 38 ms 71116 KB Output is correct
41 Correct 38 ms 71236 KB Output is correct
42 Correct 38 ms 71116 KB Output is correct
43 Correct 41 ms 71156 KB Output is correct
44 Correct 39 ms 71144 KB Output is correct
45 Correct 38 ms 71128 KB Output is correct
46 Correct 38 ms 71160 KB Output is correct
47 Correct 41 ms 71128 KB Output is correct
48 Correct 39 ms 71212 KB Output is correct
49 Correct 40 ms 71128 KB Output is correct
50 Correct 38 ms 71252 KB Output is correct
51 Correct 39 ms 71148 KB Output is correct
52 Correct 39 ms 71252 KB Output is correct
53 Correct 40 ms 71196 KB Output is correct
54 Correct 38 ms 71116 KB Output is correct
55 Correct 39 ms 71244 KB Output is correct
56 Correct 38 ms 71252 KB Output is correct
57 Correct 39 ms 71128 KB Output is correct
58 Correct 43 ms 71224 KB Output is correct
59 Correct 40 ms 71244 KB Output is correct
60 Correct 38 ms 71176 KB Output is correct
61 Correct 44 ms 71124 KB Output is correct
62 Correct 39 ms 71232 KB Output is correct
63 Correct 38 ms 71188 KB Output is correct
64 Correct 39 ms 71240 KB Output is correct
65 Runtime error 127 ms 152500 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -