답안 #373121

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
373121 2021-03-03T12:43:36 Z luciocf Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
115 ms 133996 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int maxn = 210;
const ll inf = 1e18;

int n, L;
int x[maxn], t[maxn];

ll dp[maxn][maxn][maxn][2];

int main(void)
{
	scanf("%d %d", &n, &L);

	for (int i = 1; i <= n; i++)
		scanf("%d", &x[i]);

	for (int i = 1; i <= n; i++)
		scanf("%d", &t[i]);

	for (int l = 0; l <= n; l++)
		for (int r = 0; r <= n; r++)
			for (int k = 0; k <= n; k++)
				dp[l][r][k][0] = dp[l][r][k][1] = inf;

	dp[0][0][0][0] = dp[0][0][0][1] = 0;

	x[n+1] = L;

	for (int l = 0; l <= n; l++)
	{
		for (int r = 0; r+l <= n; r++)
		{
			for (int k = 0; k <= n; k++)
			{
				ll ans = inf;

				if (l == 0 && r == 0 && k == 0) ans = 0;

				int pos_l = n-l+1;

				if (l > 0)
				{
					ll c1 = dp[l-1][r][k][0] + 1ll*x[pos_l+1] - 1ll*x[pos_l];
					ll c2 = dp[l-1][r][k][1] + 1ll*L-1ll*x[pos_l] + 1ll*x[r];

					ans = min(ans, c1);
					ans = min(ans, c2);

					if (k > 0)
					{
						c1 -= dp[l-1][r][k][0]; c1 += dp[l-1][r][k-1][0];
						c2 -= dp[l-1][r][k][1]; c2 += dp[l-1][r][k-1][1];

						if (c1 <= 1ll*t[pos_l]) ans = min(ans, c1);
						if (c2 <= 1ll*t[pos_l]) ans = min(ans, c2);
					}
				}

				dp[l][r][k][0] = ans;

				ans = inf;

				if (l == 0 && r == 0 && k == 0) ans = 0;

				if (r > 0)
				{
					ll c1 = dp[l][r-1][k][1] + 1ll*x[r] - 1ll*x[r-1];
					ll c2 = dp[l][r-1][k][0] + 1ll*L-1ll*x[pos_l] + 1ll*x[r];

					ans = min(ans, c1);
					ans = min(ans, c2);

					if (k > 0)
					{
						c1 -= dp[l][r-1][k][1]; c1 += dp[l][r-1][k-1][1];
						c2 -= dp[l][r-1][k][0]; c2 += dp[l][r-1][k-1][0];

						if (c1 <= 1ll*t[r]) ans = min(ans, c1);
						if (c2 <= 1ll*t[r]) ans = min(ans, c2);
					}
				}

				dp[l][r][k][1] = ans;
			}
		}
	}

	int ans = 0;

	for (int l = 0; l <= n; l++)
		for (int r = 0; r+l <= n; r++)
			for (int k = 0; k <= n; k++)
				if (dp[l][r][k][0] != inf || dp[l][r][k][1] != inf)
					ans = max(ans, k);

	printf("%d\n", ans);
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   17 |  scanf("%d %d", &n, &L);
      |  ~~~~~^~~~~~~~~~~~~~~~~
ho_t3.cpp:20:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   20 |   scanf("%d", &x[i]);
      |   ~~~~~^~~~~~~~~~~~~
ho_t3.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |   scanf("%d", &t[i]);
      |   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 1132 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1132 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 2 ms 1132 KB Output is correct
34 Correct 1 ms 1132 KB Output is correct
35 Correct 1 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 92 ms 107500 KB Output is correct
19 Correct 49 ms 65260 KB Output is correct
20 Correct 24 ms 34796 KB Output is correct
21 Correct 45 ms 61548 KB Output is correct
22 Correct 64 ms 79852 KB Output is correct
23 Correct 21 ms 29676 KB Output is correct
24 Correct 16 ms 23148 KB Output is correct
25 Correct 21 ms 29036 KB Output is correct
26 Correct 7 ms 11116 KB Output is correct
27 Correct 21 ms 30316 KB Output is correct
28 Correct 15 ms 21612 KB Output is correct
29 Correct 22 ms 30956 KB Output is correct
30 Correct 17 ms 24300 KB Output is correct
31 Correct 33 ms 29036 KB Output is correct
32 Correct 10 ms 15212 KB Output is correct
33 Correct 20 ms 29036 KB Output is correct
34 Correct 11 ms 10348 KB Output is correct
35 Correct 19 ms 28396 KB Output is correct
36 Correct 8 ms 13548 KB Output is correct
37 Correct 21 ms 30316 KB Output is correct
38 Correct 11 ms 16620 KB Output is correct
39 Correct 22 ms 31596 KB Output is correct
40 Correct 12 ms 18540 KB Output is correct
41 Correct 115 ms 132716 KB Output is correct
42 Correct 71 ms 89324 KB Output is correct
43 Correct 113 ms 132588 KB Output is correct
44 Correct 70 ms 88320 KB Output is correct
45 Correct 111 ms 132588 KB Output is correct
46 Correct 70 ms 89324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 1 ms 876 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 492 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 876 KB Output is correct
17 Correct 1 ms 876 KB Output is correct
18 Correct 1 ms 1132 KB Output is correct
19 Correct 1 ms 748 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 1 ms 1132 KB Output is correct
22 Correct 1 ms 620 KB Output is correct
23 Correct 1 ms 1132 KB Output is correct
24 Correct 1 ms 1004 KB Output is correct
25 Correct 1 ms 1132 KB Output is correct
26 Correct 1 ms 1132 KB Output is correct
27 Correct 1 ms 620 KB Output is correct
28 Correct 1 ms 620 KB Output is correct
29 Correct 1 ms 1132 KB Output is correct
30 Correct 1 ms 1132 KB Output is correct
31 Correct 1 ms 1132 KB Output is correct
32 Correct 1 ms 1004 KB Output is correct
33 Correct 2 ms 1132 KB Output is correct
34 Correct 1 ms 1132 KB Output is correct
35 Correct 1 ms 1132 KB Output is correct
36 Correct 92 ms 107500 KB Output is correct
37 Correct 49 ms 65260 KB Output is correct
38 Correct 24 ms 34796 KB Output is correct
39 Correct 45 ms 61548 KB Output is correct
40 Correct 64 ms 79852 KB Output is correct
41 Correct 21 ms 29676 KB Output is correct
42 Correct 16 ms 23148 KB Output is correct
43 Correct 21 ms 29036 KB Output is correct
44 Correct 7 ms 11116 KB Output is correct
45 Correct 21 ms 30316 KB Output is correct
46 Correct 15 ms 21612 KB Output is correct
47 Correct 22 ms 30956 KB Output is correct
48 Correct 17 ms 24300 KB Output is correct
49 Correct 33 ms 29036 KB Output is correct
50 Correct 10 ms 15212 KB Output is correct
51 Correct 20 ms 29036 KB Output is correct
52 Correct 11 ms 10348 KB Output is correct
53 Correct 19 ms 28396 KB Output is correct
54 Correct 8 ms 13548 KB Output is correct
55 Correct 21 ms 30316 KB Output is correct
56 Correct 11 ms 16620 KB Output is correct
57 Correct 22 ms 31596 KB Output is correct
58 Correct 12 ms 18540 KB Output is correct
59 Correct 115 ms 132716 KB Output is correct
60 Correct 71 ms 89324 KB Output is correct
61 Correct 113 ms 132588 KB Output is correct
62 Correct 70 ms 88320 KB Output is correct
63 Correct 111 ms 132588 KB Output is correct
64 Correct 70 ms 89324 KB Output is correct
65 Correct 95 ms 119660 KB Output is correct
66 Correct 91 ms 109932 KB Output is correct
67 Correct 82 ms 105196 KB Output is correct
68 Correct 75 ms 97132 KB Output is correct
69 Correct 96 ms 118508 KB Output is correct
70 Correct 92 ms 113516 KB Output is correct
71 Correct 94 ms 114796 KB Output is correct
72 Correct 95 ms 115948 KB Output is correct
73 Correct 87 ms 107500 KB Output is correct
74 Correct 80 ms 100460 KB Output is correct
75 Correct 89 ms 111084 KB Output is correct
76 Correct 113 ms 127340 KB Output is correct
77 Correct 114 ms 127340 KB Output is correct
78 Correct 77 ms 98156 KB Output is correct
79 Correct 79 ms 101612 KB Output is correct
80 Correct 106 ms 124780 KB Output is correct
81 Correct 80 ms 102764 KB Output is correct
82 Correct 85 ms 108652 KB Output is correct
83 Correct 105 ms 132588 KB Output is correct
84 Correct 90 ms 113516 KB Output is correct
85 Correct 98 ms 123500 KB Output is correct
86 Correct 99 ms 120940 KB Output is correct
87 Correct 110 ms 111212 KB Output is correct
88 Correct 110 ms 133868 KB Output is correct
89 Correct 108 ms 133868 KB Output is correct
90 Correct 97 ms 112364 KB Output is correct
91 Correct 111 ms 133996 KB Output is correct
92 Correct 109 ms 133868 KB Output is correct
93 Correct 105 ms 131308 KB Output is correct