Submission #201629

# Submission time Handle Problem Language Result Execution time Memory
201629 2020-02-11T13:04:43 Z waynetuinfor Collecting Stamps 3 (JOI20_ho_t3) C++17
100 / 100
144 ms 66808 KB
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>

int main() {
  int n, l;
  std::cin >> n >> l;
  std::vector<int> x(n + 2, 0), t(n + 2, 0);
  for (int i = 1; i <= n; ++i) std::cin >> x[i];
  for (int i = 1; i <= n; ++i) std::cin >> t[i];
  x[n + 1] = l;
  std::vector<std::vector<std::vector<std::array<int, 2>>>> dp(
      n + 2, std::vector<std::vector<std::array<int, 2>>>(
                 n + 2, std::vector<std::array<int, 2>>(n + 2)));
  constexpr int kInf = 1'000'000'000;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= n + 1; ++j) {
      for (int k = 0; k <= n + 1; ++k) {
        dp[i][j][k][0] = kInf;
        dp[i][j][k][1] = kInf;
      }
    }
  }
  dp[0][n + 1][0][0] = 0;
  dp[0][n + 1][0][1] = 0;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = n + 1; j >= 0; --j) {
      for (int k = 0; k <= n + 1; ++k) {
        if (dp[i][j][k][0] != kInf) {
          if (i + 1 < j) {
            int g = dp[i][j][k][0] + x[i + 1] - x[i];
            if (g <= t[i + 1] && k <= n) {
              dp[i + 1][j][k + 1][0] = std::min(dp[i + 1][j][k + 1][0], g);
            }
            dp[i + 1][j][k][0] = std::min(dp[i + 1][j][k][0], g);
          }
          if (j - 1 > i) {
            int g = dp[i][j][k][0] + l - (x[j - 1] - x[i]);
            if (g <= t[j - 1] && k <= n) {
              dp[i][j - 1][k + 1][1] = std::min(dp[i][j - 1][k + 1][1], g);
            }
            dp[i][j - 1][k][1] = std::min(dp[i][j - 1][k][1], g);
          }
        }
        if (dp[i][j][k][1] != kInf) {
          if (i + 1 < j) {
            int g = dp[i][j][k][1] + l - (x[j] - x[i + 1]);
            if (g <= t[i + 1] && k <= n) {
              dp[i + 1][j][k + 1][0] = std::min(dp[i + 1][j][k + 1][0], g);
            }
            dp[i + 1][j][k][0] = std::min(dp[i + 1][j][k][0], g);
          }
          if (j - 1 > i) {
            int g = dp[i][j][k][1] + x[j] - x[j - 1];
            if (g <= t[j - 1] && k <= n) {
              dp[i][j - 1][k + 1][1] = std::min(dp[i][j - 1][k + 1][1], g);
            }
            dp[i][j - 1][k][1] = std::min(dp[i][j - 1][k][1], g);
          }
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= n + 1; ++i) {
    for (int j = 0; j <= n + 1; ++j) {
      for (int k = 0; k <= n + 1; ++k) {
        if (dp[i][j][k][0] != kInf) ans = std::max(ans, k);
        if (dp[i][j][k][1] != kInf) ans = std::max(ans, k);
      }
    }
  }
  std::cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 444 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 94 ms 48120 KB Output is correct
19 Correct 49 ms 23032 KB Output is correct
20 Correct 23 ms 9336 KB Output is correct
21 Correct 46 ms 21112 KB Output is correct
22 Correct 65 ms 31224 KB Output is correct
23 Correct 22 ms 7416 KB Output is correct
24 Correct 13 ms 5244 KB Output is correct
25 Correct 21 ms 7160 KB Output is correct
26 Correct 7 ms 2040 KB Output is correct
27 Correct 22 ms 7672 KB Output is correct
28 Correct 11 ms 4728 KB Output is correct
29 Correct 23 ms 7800 KB Output is correct
30 Correct 12 ms 5624 KB Output is correct
31 Correct 18 ms 7160 KB Output is correct
32 Correct 10 ms 2936 KB Output is correct
33 Correct 18 ms 7160 KB Output is correct
34 Correct 7 ms 1912 KB Output is correct
35 Correct 15 ms 6996 KB Output is correct
36 Correct 8 ms 2552 KB Output is correct
37 Correct 17 ms 7672 KB Output is correct
38 Correct 10 ms 3320 KB Output is correct
39 Correct 18 ms 8184 KB Output is correct
40 Correct 12 ms 3832 KB Output is correct
41 Correct 139 ms 65400 KB Output is correct
42 Correct 52 ms 36600 KB Output is correct
43 Correct 140 ms 65400 KB Output is correct
44 Correct 50 ms 36088 KB Output is correct
45 Correct 144 ms 65528 KB Output is correct
46 Correct 53 ms 36472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 256 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 256 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 444 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 94 ms 48120 KB Output is correct
37 Correct 49 ms 23032 KB Output is correct
38 Correct 23 ms 9336 KB Output is correct
39 Correct 46 ms 21112 KB Output is correct
40 Correct 65 ms 31224 KB Output is correct
41 Correct 22 ms 7416 KB Output is correct
42 Correct 13 ms 5244 KB Output is correct
43 Correct 21 ms 7160 KB Output is correct
44 Correct 7 ms 2040 KB Output is correct
45 Correct 22 ms 7672 KB Output is correct
46 Correct 11 ms 4728 KB Output is correct
47 Correct 23 ms 7800 KB Output is correct
48 Correct 12 ms 5624 KB Output is correct
49 Correct 18 ms 7160 KB Output is correct
50 Correct 10 ms 2936 KB Output is correct
51 Correct 18 ms 7160 KB Output is correct
52 Correct 7 ms 1912 KB Output is correct
53 Correct 15 ms 6996 KB Output is correct
54 Correct 8 ms 2552 KB Output is correct
55 Correct 17 ms 7672 KB Output is correct
56 Correct 10 ms 3320 KB Output is correct
57 Correct 18 ms 8184 KB Output is correct
58 Correct 12 ms 3832 KB Output is correct
59 Correct 139 ms 65400 KB Output is correct
60 Correct 52 ms 36600 KB Output is correct
61 Correct 140 ms 65400 KB Output is correct
62 Correct 50 ms 36088 KB Output is correct
63 Correct 144 ms 65528 KB Output is correct
64 Correct 53 ms 36472 KB Output is correct
65 Correct 92 ms 56304 KB Output is correct
66 Correct 89 ms 49532 KB Output is correct
67 Correct 79 ms 46508 KB Output is correct
68 Correct 71 ms 41592 KB Output is correct
69 Correct 97 ms 55672 KB Output is correct
70 Correct 102 ms 52344 KB Output is correct
71 Correct 78 ms 52856 KB Output is correct
72 Correct 103 ms 54008 KB Output is correct
73 Correct 69 ms 48120 KB Output is correct
74 Correct 86 ms 43512 KB Output is correct
75 Correct 76 ms 50808 KB Output is correct
76 Correct 109 ms 61692 KB Output is correct
77 Correct 94 ms 61688 KB Output is correct
78 Correct 78 ms 41976 KB Output is correct
79 Correct 70 ms 44536 KB Output is correct
80 Correct 109 ms 59896 KB Output is correct
81 Correct 65 ms 44920 KB Output is correct
82 Correct 82 ms 49016 KB Output is correct
83 Correct 98 ms 65400 KB Output is correct
84 Correct 88 ms 52468 KB Output is correct
85 Correct 85 ms 59256 KB Output is correct
86 Correct 100 ms 57464 KB Output is correct
87 Correct 79 ms 50680 KB Output is correct
88 Correct 134 ms 66808 KB Output is correct
89 Correct 114 ms 66808 KB Output is correct
90 Correct 70 ms 51192 KB Output is correct
91 Correct 128 ms 66808 KB Output is correct
92 Correct 113 ms 66808 KB Output is correct
93 Correct 85 ms 64996 KB Output is correct