답안 #207759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
207759 2020-03-08T20:41:03 Z super_j6 Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
100 ms 128764 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second

const long long inf = 1000000000000000007;
const int maxn = 202;
int n, m;
pi a[maxn];
long long dp[maxn][maxn][maxn][2];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> m;
	
	for(int i = 1; i <= n; i++) cin >> a[i].f;
	for(int i = 1; i <= n; i++) cin >> a[i].s;
	a[n + 1].f = m;
	sort(a + 1, a + n + 1);
	
	for(int i = 0; i <= n; i++)
	for(int j = 0; j <= n; j++)
	for(int k = n + 1; k > j; k--) dp[i][j][k][0] = dp[i][j][k][1] = inf;
	
	int ret = 0;
	dp[0][0][n + 1][0] = dp[0][0][n + 1][1] = 0;
	for(int i = 0; i <= n; i++)
	for(int j = 0; j <= n; j++)
	for(int k = n + 1; k > j; k--){
		long long x;
		if(dp[i][j][k][0] != inf){
			ret = i;
			x = dp[i][j][k][0] + a[j + 1].f - a[j].f;
			dp[i][j + 1][k][0] = min(dp[i][j + 1][k][0], x);
			if(x <= a[j + 1].s) dp[i + 1][j + 1][k][0] = min(dp[i + 1][j + 1][k][0], x);
			x = dp[i][j][k][0] + a[j].f + m - a[k - 1].f;
			dp[i][j][k - 1][1] = min(dp[i][j][k - 1][1], x);
			if(x <= a[k - 1].s) dp[i + 1][j][k - 1][1] = min(dp[i + 1][j][k - 1][1], x);
		}
		if(dp[i][j][k][1] != inf){
			ret = i;
			x = dp[i][j][k][1] + a[k].f - a[k - 1].f;
			dp[i][j][k - 1][1] = min(dp[i][j][k - 1][1], x);
			if(x <= a[k - 1].s) dp[i + 1][j][k - 1][1] = min(dp[i + 1][j][k - 1][1], x);
			x = dp[i][j][k][1] + a[j + 1].f + m - a[k].f;
			dp[i][j + 1][k][0] = min(dp[i][j + 1][k][0], x);
			if(x <= a[j + 1].s) dp[i + 1][j + 1][k][0] = min(dp[i + 1][j + 1][k][0], x);
		}
	}
	
	cout << ret << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 888 KB Output is correct
17 Correct 5 ms 1016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 888 KB Output is correct
17 Correct 5 ms 1016 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 5 ms 760 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 5 ms 636 KB Output is correct
23 Correct 5 ms 1144 KB Output is correct
24 Correct 5 ms 1016 KB Output is correct
25 Correct 5 ms 1144 KB Output is correct
26 Correct 6 ms 1144 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 1272 KB Output is correct
30 Correct 5 ms 1272 KB Output is correct
31 Correct 5 ms 1144 KB Output is correct
32 Correct 5 ms 1016 KB Output is correct
33 Correct 5 ms 1272 KB Output is correct
34 Correct 5 ms 1272 KB Output is correct
35 Correct 5 ms 1272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 888 KB Output is correct
17 Correct 5 ms 1016 KB Output is correct
18 Correct 69 ms 103760 KB Output is correct
19 Correct 44 ms 63096 KB Output is correct
20 Correct 23 ms 33784 KB Output is correct
21 Correct 40 ms 59512 KB Output is correct
22 Correct 52 ms 77176 KB Output is correct
23 Correct 22 ms 28792 KB Output is correct
24 Correct 16 ms 22392 KB Output is correct
25 Correct 21 ms 28152 KB Output is correct
26 Correct 10 ms 10744 KB Output is correct
27 Correct 23 ms 29432 KB Output is correct
28 Correct 15 ms 20984 KB Output is correct
29 Correct 22 ms 29944 KB Output is correct
30 Correct 17 ms 23416 KB Output is correct
31 Correct 26 ms 28152 KB Output is correct
32 Correct 15 ms 14840 KB Output is correct
33 Correct 21 ms 28152 KB Output is correct
34 Correct 10 ms 10104 KB Output is correct
35 Correct 18 ms 27384 KB Output is correct
36 Correct 11 ms 13052 KB Output is correct
37 Correct 20 ms 29176 KB Output is correct
38 Correct 13 ms 16120 KB Output is correct
39 Correct 21 ms 30456 KB Output is correct
40 Correct 14 ms 17912 KB Output is correct
41 Correct 100 ms 127992 KB Output is correct
42 Correct 52 ms 86008 KB Output is correct
43 Correct 93 ms 127992 KB Output is correct
44 Correct 51 ms 84984 KB Output is correct
45 Correct 90 ms 127984 KB Output is correct
46 Correct 52 ms 86004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 632 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 504 KB Output is correct
6 Correct 5 ms 888 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 5 ms 760 KB Output is correct
9 Correct 5 ms 888 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 888 KB Output is correct
13 Correct 5 ms 888 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 5 ms 888 KB Output is correct
17 Correct 5 ms 1016 KB Output is correct
18 Correct 5 ms 1144 KB Output is correct
19 Correct 5 ms 760 KB Output is correct
20 Correct 5 ms 888 KB Output is correct
21 Correct 5 ms 1144 KB Output is correct
22 Correct 5 ms 636 KB Output is correct
23 Correct 5 ms 1144 KB Output is correct
24 Correct 5 ms 1016 KB Output is correct
25 Correct 5 ms 1144 KB Output is correct
26 Correct 6 ms 1144 KB Output is correct
27 Correct 5 ms 632 KB Output is correct
28 Correct 5 ms 632 KB Output is correct
29 Correct 5 ms 1272 KB Output is correct
30 Correct 5 ms 1272 KB Output is correct
31 Correct 5 ms 1144 KB Output is correct
32 Correct 5 ms 1016 KB Output is correct
33 Correct 5 ms 1272 KB Output is correct
34 Correct 5 ms 1272 KB Output is correct
35 Correct 5 ms 1272 KB Output is correct
36 Correct 69 ms 103760 KB Output is correct
37 Correct 44 ms 63096 KB Output is correct
38 Correct 23 ms 33784 KB Output is correct
39 Correct 40 ms 59512 KB Output is correct
40 Correct 52 ms 77176 KB Output is correct
41 Correct 22 ms 28792 KB Output is correct
42 Correct 16 ms 22392 KB Output is correct
43 Correct 21 ms 28152 KB Output is correct
44 Correct 10 ms 10744 KB Output is correct
45 Correct 23 ms 29432 KB Output is correct
46 Correct 15 ms 20984 KB Output is correct
47 Correct 22 ms 29944 KB Output is correct
48 Correct 17 ms 23416 KB Output is correct
49 Correct 26 ms 28152 KB Output is correct
50 Correct 15 ms 14840 KB Output is correct
51 Correct 21 ms 28152 KB Output is correct
52 Correct 10 ms 10104 KB Output is correct
53 Correct 18 ms 27384 KB Output is correct
54 Correct 11 ms 13052 KB Output is correct
55 Correct 20 ms 29176 KB Output is correct
56 Correct 13 ms 16120 KB Output is correct
57 Correct 21 ms 30456 KB Output is correct
58 Correct 14 ms 17912 KB Output is correct
59 Correct 100 ms 127992 KB Output is correct
60 Correct 52 ms 86008 KB Output is correct
61 Correct 93 ms 127992 KB Output is correct
62 Correct 51 ms 84984 KB Output is correct
63 Correct 90 ms 127984 KB Output is correct
64 Correct 52 ms 86004 KB Output is correct
65 Correct 80 ms 115552 KB Output is correct
66 Correct 72 ms 106104 KB Output is correct
67 Correct 67 ms 101496 KB Output is correct
68 Correct 63 ms 93816 KB Output is correct
69 Correct 77 ms 114428 KB Output is correct
70 Correct 87 ms 109816 KB Output is correct
71 Correct 69 ms 110584 KB Output is correct
72 Correct 85 ms 112120 KB Output is correct
73 Correct 64 ms 103800 KB Output is correct
74 Correct 76 ms 97144 KB Output is correct
75 Correct 69 ms 107128 KB Output is correct
76 Correct 90 ms 122872 KB Output is correct
77 Correct 79 ms 122876 KB Output is correct
78 Correct 73 ms 94824 KB Output is correct
79 Correct 68 ms 98168 KB Output is correct
80 Correct 90 ms 120440 KB Output is correct
81 Correct 63 ms 99192 KB Output is correct
82 Correct 67 ms 104824 KB Output is correct
83 Correct 83 ms 127864 KB Output is correct
84 Correct 72 ms 109432 KB Output is correct
85 Correct 74 ms 119288 KB Output is correct
86 Correct 77 ms 116600 KB Output is correct
87 Correct 70 ms 107256 KB Output is correct
88 Correct 98 ms 128760 KB Output is correct
89 Correct 92 ms 128760 KB Output is correct
90 Correct 64 ms 108280 KB Output is correct
91 Correct 98 ms 128764 KB Output is correct
92 Correct 93 ms 128760 KB Output is correct
93 Correct 76 ms 126320 KB Output is correct