답안 #883121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883121 2023-12-04T14:57:54 Z vjudge1 Coin Collecting (JOI19_ho_t4) C++17
37 / 100
217 ms 274432 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int inf = 1e18 + 7;//wa alırsa bunu değiştir !!!
inline int dist(pair < int , int > a , pair < int , int > b){
	return abs(a.first-b.first) + abs(a.second-b.second);
}
void solve(){
	int n;cin >> n;
	pair < int , int > point[2*n];
	for(int i = 0;i<2*n;i++){
		cin >> point[i].first >> point[i].second;
	}
	sort(point , point + 2*n);
	//cout << "points : ";for(int i = 0;i<2*n;i++)cout << point[i].first << "," << point[i].second << "    ";cout << endl;
	int dp[2*n+1][n+1];
	for(int i = 0;i<=2*n;i++){
		for(int j = 0;j<=n;j++){
			dp[i][j] = inf;
		}
	}
	dp[0][0] = 0;
	for(int i = 1;i<=2*n;i++){
		for(int j = 0;j<=min(i,n);j++){
			//önceki üst satıra geldi
			if(j != 0){
				dp[i][j] = min(dp[i][j] , dp[i-1][j-1] + dist(point[i-1],{j,2}) );
			}
			//önceki alt satıra geldi
			dp[i][j] = min(dp[i][j] , dp[i-1][j] + dist(point[i-1],{i-j,1}) );
			//cout << i << " " << j << " : " << dp[i][j] << endl;
		}
	}
	cout << dp[2*n][n] << endl;
}
signed main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int testcase = 1;//cin >> testcase;
	while(testcase--)solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 372 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 424 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 456 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 372 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 424 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 456 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 12 ms 16056 KB Output is correct
35 Correct 12 ms 15960 KB Output is correct
36 Correct 12 ms 15964 KB Output is correct
37 Correct 13 ms 16088 KB Output is correct
38 Correct 14 ms 16088 KB Output is correct
39 Correct 14 ms 16188 KB Output is correct
40 Correct 16 ms 15964 KB Output is correct
41 Correct 12 ms 16132 KB Output is correct
42 Correct 12 ms 15960 KB Output is correct
43 Correct 12 ms 16196 KB Output is correct
44 Correct 12 ms 15972 KB Output is correct
45 Correct 12 ms 15964 KB Output is correct
46 Correct 12 ms 16080 KB Output is correct
47 Correct 12 ms 16124 KB Output is correct
48 Correct 12 ms 15960 KB Output is correct
49 Correct 12 ms 15968 KB Output is correct
50 Correct 12 ms 16188 KB Output is correct
51 Correct 12 ms 15964 KB Output is correct
52 Correct 14 ms 16336 KB Output is correct
53 Correct 15 ms 15960 KB Output is correct
54 Correct 13 ms 15964 KB Output is correct
55 Correct 12 ms 15964 KB Output is correct
56 Correct 12 ms 15964 KB Output is correct
57 Correct 12 ms 15956 KB Output is correct
58 Correct 12 ms 15960 KB Output is correct
59 Correct 12 ms 15964 KB Output is correct
60 Correct 12 ms 15964 KB Output is correct
61 Correct 12 ms 16184 KB Output is correct
62 Correct 12 ms 16188 KB Output is correct
63 Correct 12 ms 16336 KB Output is correct
64 Correct 12 ms 16080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 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 372 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 424 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 456 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 12 ms 16056 KB Output is correct
35 Correct 12 ms 15960 KB Output is correct
36 Correct 12 ms 15964 KB Output is correct
37 Correct 13 ms 16088 KB Output is correct
38 Correct 14 ms 16088 KB Output is correct
39 Correct 14 ms 16188 KB Output is correct
40 Correct 16 ms 15964 KB Output is correct
41 Correct 12 ms 16132 KB Output is correct
42 Correct 12 ms 15960 KB Output is correct
43 Correct 12 ms 16196 KB Output is correct
44 Correct 12 ms 15972 KB Output is correct
45 Correct 12 ms 15964 KB Output is correct
46 Correct 12 ms 16080 KB Output is correct
47 Correct 12 ms 16124 KB Output is correct
48 Correct 12 ms 15960 KB Output is correct
49 Correct 12 ms 15968 KB Output is correct
50 Correct 12 ms 16188 KB Output is correct
51 Correct 12 ms 15964 KB Output is correct
52 Correct 14 ms 16336 KB Output is correct
53 Correct 15 ms 15960 KB Output is correct
54 Correct 13 ms 15964 KB Output is correct
55 Correct 12 ms 15964 KB Output is correct
56 Correct 12 ms 15964 KB Output is correct
57 Correct 12 ms 15956 KB Output is correct
58 Correct 12 ms 15960 KB Output is correct
59 Correct 12 ms 15964 KB Output is correct
60 Correct 12 ms 15964 KB Output is correct
61 Correct 12 ms 16184 KB Output is correct
62 Correct 12 ms 16188 KB Output is correct
63 Correct 12 ms 16336 KB Output is correct
64 Correct 12 ms 16080 KB Output is correct
65 Runtime error 217 ms 274432 KB Execution killed with signal 9
66 Halted 0 ms 0 KB -