답안 #532116

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532116 2022-03-02T06:10:18 Z rk42745417 Coin Collecting (JOI19_ho_t4) C++17
37 / 100
1000 ms 5504 KB
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(4e15) + ll(2e15);
const double EPS = 1e-9;
static int LamyIsCute = []() {
	EmiliaMyWife
		return 48763;
}();

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,tune=native")
const int N = 1e5 + 25;
ll dp[2][N * 2];
pair<ll, ll> arr[N * 2];
signed main() {
	int n;
	cin >> n;
	for(int i = 0; i < n * 2; i++)
		cin >> arr[i].first >> arr[i].second;
	sort(arr, arr + n * 2);
	int prv = 0, nxt = 1;

	dp[prv][0] = 0;
	for(int s = 0; s < n * 2; s++) {
		for(int i = 0; i <= s + 1; i++)
			dp[nxt][i] = LINF;

		for(int i = max(0, s - n); i <= min(n, s); i++) {
			int j = s - i;
			if(i < n)
				dp[nxt][i + 1] = min(dp[nxt][i + 1], dp[prv][i] + abs(arr[s].first - (i + 1)) + abs(arr[s].second - 2));
			if(j < n)
				dp[nxt][i] = min(dp[nxt][i], dp[prv][i] + abs(arr[s].first - (j + 1)) + abs(arr[s].second - 1));
		}
		swap(nxt, prv);
	}
	cout << dp[prv][n] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 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 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 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 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 4 ms 332 KB Output is correct
35 Correct 5 ms 332 KB Output is correct
36 Correct 5 ms 372 KB Output is correct
37 Correct 5 ms 332 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 5 ms 332 KB Output is correct
40 Correct 5 ms 332 KB Output is correct
41 Correct 6 ms 332 KB Output is correct
42 Correct 6 ms 332 KB Output is correct
43 Correct 4 ms 376 KB Output is correct
44 Correct 4 ms 332 KB Output is correct
45 Correct 4 ms 332 KB Output is correct
46 Correct 4 ms 332 KB Output is correct
47 Correct 4 ms 332 KB Output is correct
48 Correct 4 ms 332 KB Output is correct
49 Correct 5 ms 332 KB Output is correct
50 Correct 4 ms 332 KB Output is correct
51 Correct 4 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
53 Correct 4 ms 332 KB Output is correct
54 Correct 5 ms 388 KB Output is correct
55 Correct 7 ms 332 KB Output is correct
56 Correct 5 ms 332 KB Output is correct
57 Correct 7 ms 332 KB Output is correct
58 Correct 5 ms 332 KB Output is correct
59 Correct 5 ms 332 KB Output is correct
60 Correct 6 ms 380 KB Output is correct
61 Correct 5 ms 332 KB Output is correct
62 Correct 4 ms 332 KB Output is correct
63 Correct 5 ms 332 KB Output is correct
64 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 332 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 0 ms 332 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 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 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 204 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 1 ms 204 KB Output is correct
34 Correct 4 ms 332 KB Output is correct
35 Correct 5 ms 332 KB Output is correct
36 Correct 5 ms 372 KB Output is correct
37 Correct 5 ms 332 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 5 ms 332 KB Output is correct
40 Correct 5 ms 332 KB Output is correct
41 Correct 6 ms 332 KB Output is correct
42 Correct 6 ms 332 KB Output is correct
43 Correct 4 ms 376 KB Output is correct
44 Correct 4 ms 332 KB Output is correct
45 Correct 4 ms 332 KB Output is correct
46 Correct 4 ms 332 KB Output is correct
47 Correct 4 ms 332 KB Output is correct
48 Correct 4 ms 332 KB Output is correct
49 Correct 5 ms 332 KB Output is correct
50 Correct 4 ms 332 KB Output is correct
51 Correct 4 ms 332 KB Output is correct
52 Correct 4 ms 332 KB Output is correct
53 Correct 4 ms 332 KB Output is correct
54 Correct 5 ms 388 KB Output is correct
55 Correct 7 ms 332 KB Output is correct
56 Correct 5 ms 332 KB Output is correct
57 Correct 7 ms 332 KB Output is correct
58 Correct 5 ms 332 KB Output is correct
59 Correct 5 ms 332 KB Output is correct
60 Correct 6 ms 380 KB Output is correct
61 Correct 5 ms 332 KB Output is correct
62 Correct 4 ms 332 KB Output is correct
63 Correct 5 ms 332 KB Output is correct
64 Correct 4 ms 384 KB Output is correct
65 Execution timed out 1075 ms 5504 KB Time limit exceeded
66 Halted 0 ms 0 KB -