Submission #332299

# Submission time Handle Problem Language Result Execution time Memory
332299 2020-12-02T01:57:49 Z ChrisT Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
86 ms 67920 KB
#include <bits/stdc++.h>
using namespace std;
int dp[205][205][205][2]; //[L][R][got][where]
int main () {
	int n,p;
	scanf ("%d %d",&n,&p);
	auto dist = [&] (int a, int b) {int d = abs(a-b); return min(d,p-d);};
	vector<int> pos(n+1), t(n+1);
	for (int i = 1; i <= n; i++) scanf ("%d",&pos[i]);
	for (int i = 1; i <= n; i++) scanf ("%d",&t[i]);
	memset(dp,0x3f,sizeof dp);
	dp[0][0][0][0] = dp[0][0][0][1] = 0; int ret = 0; ++n;
	for (int len = 2; len <= n; len++) {
		for (int st = 1 - len; st <= 0; st++) {
			int l = (st + n) % n, r = (l + len - 1) % n;
			for (int taken = 0; taken < len; taken++) {
				int l2 = (l + 1) % n, r2 = (r - 1 + n) % n;
				dp[l][r][taken][0] = min({dp[l][r][taken][0],dp[l2][r][taken][0] + dist(pos[l2],pos[l]), dp[l2][r][taken][1] + dist(pos[r],pos[l])});
				dp[l][r][taken][1] = min({dp[l][r][taken][1],dp[l][r2][taken][0] + dist(pos[l],pos[r]), dp[l][r2][taken][1] + dist(pos[r2],pos[r])});
				if (taken) {
					if (dp[l2][r][taken-1][0] + dist(pos[l2],pos[l]) <= t[l]) {
						dp[l][r][taken][0] = min(dp[l][r][taken][0],dp[l2][r][taken-1][0] + dist(pos[l2],pos[l]));
					}
					if (dp[l2][r][taken-1][1] + dist(pos[l],pos[r]) <= t[l]) {
						dp[l][r][taken][0] = min(dp[l][r][taken][0],dp[l2][r][taken-1][1] + dist(pos[l],pos[r]));
					}
					if (dp[l][r2][taken-1][0] + dist(pos[l],pos[r]) <= t[r]) {
						dp[l][r][taken][1] = min(dp[l][r][taken][1],dp[l][r2][taken-1][0] + dist(pos[l],pos[r]));
					}
					if (dp[l][r2][taken-1][1] + dist(pos[r2],pos[r]) <= t[r]) {
						dp[l][r][taken][1] = min(dp[l][r][taken][1],dp[l][r2][taken-1][1] + dist(pos[r2],pos[r]));
					}
				}
				if (min(dp[l][r][taken][0],dp[l][r][taken][1]) <= 1'000'000'000) ret = max(ret,taken);
			}
		}
	}
	printf ("%d\n",ret);
	return 0;
}

Compilation message

ho_t3.cpp: In function 'int main()':
ho_t3.cpp:6:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    6 |  scanf ("%d %d",&n,&p);
      |  ~~~~~~^~~~~~~~~~~~~~~
ho_t3.cpp:9:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |  for (int i = 1; i <= n; i++) scanf ("%d",&pos[i]);
      |                               ~~~~~~^~~~~~~~~~~~~~
ho_t3.cpp:10:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |  for (int i = 1; i <= n; i++) scanf ("%d",&t[i]);
      |                               ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 37 ms 67840 KB Output is correct
2 Correct 37 ms 67692 KB Output is correct
3 Correct 36 ms 67820 KB Output is correct
4 Correct 42 ms 67692 KB Output is correct
5 Correct 37 ms 67692 KB Output is correct
6 Correct 37 ms 67692 KB Output is correct
7 Correct 37 ms 67692 KB Output is correct
8 Correct 37 ms 67692 KB Output is correct
9 Correct 37 ms 67692 KB Output is correct
10 Correct 37 ms 67692 KB Output is correct
11 Correct 37 ms 67692 KB Output is correct
12 Correct 38 ms 67692 KB Output is correct
13 Correct 37 ms 67692 KB Output is correct
14 Correct 36 ms 67692 KB Output is correct
15 Correct 37 ms 67692 KB Output is correct
16 Correct 40 ms 67692 KB Output is correct
17 Correct 38 ms 67692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 67840 KB Output is correct
2 Correct 37 ms 67692 KB Output is correct
3 Correct 36 ms 67820 KB Output is correct
4 Correct 42 ms 67692 KB Output is correct
5 Correct 37 ms 67692 KB Output is correct
6 Correct 37 ms 67692 KB Output is correct
7 Correct 37 ms 67692 KB Output is correct
8 Correct 37 ms 67692 KB Output is correct
9 Correct 37 ms 67692 KB Output is correct
10 Correct 37 ms 67692 KB Output is correct
11 Correct 37 ms 67692 KB Output is correct
12 Correct 38 ms 67692 KB Output is correct
13 Correct 37 ms 67692 KB Output is correct
14 Correct 36 ms 67692 KB Output is correct
15 Correct 37 ms 67692 KB Output is correct
16 Correct 40 ms 67692 KB Output is correct
17 Correct 38 ms 67692 KB Output is correct
18 Correct 36 ms 67692 KB Output is correct
19 Correct 37 ms 67692 KB Output is correct
20 Correct 37 ms 67692 KB Output is correct
21 Correct 37 ms 67820 KB Output is correct
22 Correct 37 ms 67820 KB Output is correct
23 Correct 37 ms 67692 KB Output is correct
24 Correct 37 ms 67692 KB Output is correct
25 Correct 39 ms 67692 KB Output is correct
26 Correct 44 ms 67692 KB Output is correct
27 Correct 38 ms 67692 KB Output is correct
28 Correct 38 ms 67820 KB Output is correct
29 Correct 36 ms 67692 KB Output is correct
30 Correct 37 ms 67692 KB Output is correct
31 Correct 37 ms 67692 KB Output is correct
32 Correct 37 ms 67692 KB Output is correct
33 Correct 39 ms 67692 KB Output is correct
34 Correct 37 ms 67820 KB Output is correct
35 Correct 38 ms 67692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 67840 KB Output is correct
2 Correct 37 ms 67692 KB Output is correct
3 Correct 36 ms 67820 KB Output is correct
4 Correct 42 ms 67692 KB Output is correct
5 Correct 37 ms 67692 KB Output is correct
6 Correct 37 ms 67692 KB Output is correct
7 Correct 37 ms 67692 KB Output is correct
8 Correct 37 ms 67692 KB Output is correct
9 Correct 37 ms 67692 KB Output is correct
10 Correct 37 ms 67692 KB Output is correct
11 Correct 37 ms 67692 KB Output is correct
12 Correct 38 ms 67692 KB Output is correct
13 Correct 37 ms 67692 KB Output is correct
14 Correct 36 ms 67692 KB Output is correct
15 Correct 37 ms 67692 KB Output is correct
16 Correct 40 ms 67692 KB Output is correct
17 Correct 38 ms 67692 KB Output is correct
18 Correct 80 ms 67692 KB Output is correct
19 Correct 50 ms 67692 KB Output is correct
20 Correct 42 ms 67692 KB Output is correct
21 Correct 51 ms 67820 KB Output is correct
22 Correct 66 ms 67692 KB Output is correct
23 Correct 48 ms 67692 KB Output is correct
24 Correct 39 ms 67692 KB Output is correct
25 Correct 41 ms 67692 KB Output is correct
26 Correct 38 ms 67692 KB Output is correct
27 Correct 42 ms 67692 KB Output is correct
28 Correct 40 ms 67692 KB Output is correct
29 Correct 46 ms 67820 KB Output is correct
30 Correct 40 ms 67820 KB Output is correct
31 Correct 41 ms 67692 KB Output is correct
32 Correct 38 ms 67692 KB Output is correct
33 Correct 42 ms 67692 KB Output is correct
34 Correct 37 ms 67692 KB Output is correct
35 Correct 41 ms 67692 KB Output is correct
36 Correct 37 ms 67692 KB Output is correct
37 Correct 43 ms 67692 KB Output is correct
38 Correct 38 ms 67692 KB Output is correct
39 Correct 41 ms 67692 KB Output is correct
40 Correct 39 ms 67692 KB Output is correct
41 Correct 77 ms 67820 KB Output is correct
42 Correct 63 ms 67692 KB Output is correct
43 Correct 79 ms 67692 KB Output is correct
44 Correct 59 ms 67692 KB Output is correct
45 Correct 76 ms 67920 KB Output is correct
46 Correct 60 ms 67692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 67840 KB Output is correct
2 Correct 37 ms 67692 KB Output is correct
3 Correct 36 ms 67820 KB Output is correct
4 Correct 42 ms 67692 KB Output is correct
5 Correct 37 ms 67692 KB Output is correct
6 Correct 37 ms 67692 KB Output is correct
7 Correct 37 ms 67692 KB Output is correct
8 Correct 37 ms 67692 KB Output is correct
9 Correct 37 ms 67692 KB Output is correct
10 Correct 37 ms 67692 KB Output is correct
11 Correct 37 ms 67692 KB Output is correct
12 Correct 38 ms 67692 KB Output is correct
13 Correct 37 ms 67692 KB Output is correct
14 Correct 36 ms 67692 KB Output is correct
15 Correct 37 ms 67692 KB Output is correct
16 Correct 40 ms 67692 KB Output is correct
17 Correct 38 ms 67692 KB Output is correct
18 Correct 36 ms 67692 KB Output is correct
19 Correct 37 ms 67692 KB Output is correct
20 Correct 37 ms 67692 KB Output is correct
21 Correct 37 ms 67820 KB Output is correct
22 Correct 37 ms 67820 KB Output is correct
23 Correct 37 ms 67692 KB Output is correct
24 Correct 37 ms 67692 KB Output is correct
25 Correct 39 ms 67692 KB Output is correct
26 Correct 44 ms 67692 KB Output is correct
27 Correct 38 ms 67692 KB Output is correct
28 Correct 38 ms 67820 KB Output is correct
29 Correct 36 ms 67692 KB Output is correct
30 Correct 37 ms 67692 KB Output is correct
31 Correct 37 ms 67692 KB Output is correct
32 Correct 37 ms 67692 KB Output is correct
33 Correct 39 ms 67692 KB Output is correct
34 Correct 37 ms 67820 KB Output is correct
35 Correct 38 ms 67692 KB Output is correct
36 Correct 80 ms 67692 KB Output is correct
37 Correct 50 ms 67692 KB Output is correct
38 Correct 42 ms 67692 KB Output is correct
39 Correct 51 ms 67820 KB Output is correct
40 Correct 66 ms 67692 KB Output is correct
41 Correct 48 ms 67692 KB Output is correct
42 Correct 39 ms 67692 KB Output is correct
43 Correct 41 ms 67692 KB Output is correct
44 Correct 38 ms 67692 KB Output is correct
45 Correct 42 ms 67692 KB Output is correct
46 Correct 40 ms 67692 KB Output is correct
47 Correct 46 ms 67820 KB Output is correct
48 Correct 40 ms 67820 KB Output is correct
49 Correct 41 ms 67692 KB Output is correct
50 Correct 38 ms 67692 KB Output is correct
51 Correct 42 ms 67692 KB Output is correct
52 Correct 37 ms 67692 KB Output is correct
53 Correct 41 ms 67692 KB Output is correct
54 Correct 37 ms 67692 KB Output is correct
55 Correct 43 ms 67692 KB Output is correct
56 Correct 38 ms 67692 KB Output is correct
57 Correct 41 ms 67692 KB Output is correct
58 Correct 39 ms 67692 KB Output is correct
59 Correct 77 ms 67820 KB Output is correct
60 Correct 63 ms 67692 KB Output is correct
61 Correct 79 ms 67692 KB Output is correct
62 Correct 59 ms 67692 KB Output is correct
63 Correct 76 ms 67920 KB Output is correct
64 Correct 60 ms 67692 KB Output is correct
65 Correct 71 ms 67820 KB Output is correct
66 Correct 65 ms 67692 KB Output is correct
67 Correct 65 ms 67820 KB Output is correct
68 Correct 61 ms 67692 KB Output is correct
69 Correct 71 ms 67820 KB Output is correct
70 Correct 81 ms 67692 KB Output is correct
71 Correct 67 ms 67692 KB Output is correct
72 Correct 77 ms 67692 KB Output is correct
73 Correct 66 ms 67692 KB Output is correct
74 Correct 74 ms 67692 KB Output is correct
75 Correct 68 ms 67692 KB Output is correct
76 Correct 79 ms 67692 KB Output is correct
77 Correct 75 ms 67692 KB Output is correct
78 Correct 65 ms 67692 KB Output is correct
79 Correct 64 ms 67692 KB Output is correct
80 Correct 78 ms 67692 KB Output is correct
81 Correct 65 ms 67692 KB Output is correct
82 Correct 83 ms 67692 KB Output is correct
83 Correct 75 ms 67692 KB Output is correct
84 Correct 71 ms 67820 KB Output is correct
85 Correct 71 ms 67692 KB Output is correct
86 Correct 86 ms 67820 KB Output is correct
87 Correct 78 ms 67692 KB Output is correct
88 Correct 81 ms 67820 KB Output is correct
89 Correct 78 ms 67692 KB Output is correct
90 Correct 65 ms 67692 KB Output is correct
91 Correct 80 ms 67692 KB Output is correct
92 Correct 77 ms 67692 KB Output is correct
93 Correct 79 ms 67692 KB Output is correct