Submission #244886

# Submission time Handle Problem Language Result Execution time Memory
244886 2020-07-05T08:31:55 Z rama_pang Collecting Stamps 3 (JOI20_ho_t3) C++14
100 / 100
1415 ms 147712 KB
#include <bits/stdc++.h>
using namespace std;

using lint = long long;
const int MAXN = 205;

int N, L;
int X[MAXN], T[MAXN];
lint dist[MAXN][MAXN][2][MAXN];

struct State {
  int left;
  int right;
  int pos_right;
  int stamps;
  State() {}
  State(int l, int r, int p, int s) : left(l), right(r), pos_right(p), stamps(s) {}
  bool operator < (const State &o) const {
    return stamps < o.stamps;
  }
};

int Distance(int a, int b) {
  if (a > b) swap(a, b);
  return min(X[b] - X[a], X[a] + L - X[b]);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  memset(dist, -1, sizeof(dist));

  cin >> N >> L;
  for (int i = 1; i <= N; i++) {
    cin >> X[i];
  }
  X[N + 1] = L;
  for (int i = 1; i <= N; i++) {
    cin >> T[i];
  }
  priority_queue<pair<lint, State>, vector<pair<lint, State>>, greater<pair<lint, State>>> pq;
  pq.emplace(0, State(0, N + 1, 0, 0));
  dist[0][N + 1][0][0] = 0;
  int ans = 0;
  while (!pq.empty()) {
    int left = pq.top().second.left;
    int right = pq.top().second.right;
    int pos_right = pq.top().second.pos_right;
    int stamps = pq.top().second.stamps;
    lint dt = pq.top().first;
    pq.pop();
    ans = max(ans, stamps);
    if (dt > 1e9 || left > right || dist[left][right][pos_right][stamps] != dt) {
      continue;
    }
    int cur = pos_right ? right : left;
    if (left + 1 < right) {
      lint &nxt = dist[left + 1][right][0][stamps + (dt + Distance(left + 1, cur) <= T[left + 1])];
      if (nxt == -1 || nxt > dt + Distance(left + 1, cur)) {
        nxt = dt + Distance(left + 1, cur);
        pq.emplace(nxt, State(left + 1, right, 0, stamps + (dt + Distance(left + 1, cur) <= T[left + 1])));
      }
    }
    if (left < right - 1) {
      lint &nxt = dist[left][right - 1][1][stamps + (dt + Distance(right - 1, cur) <= T[right - 1])];
      if (nxt == -1 || nxt > dt + Distance(right - 1, cur)) {
        nxt = dt + Distance(right - 1, cur);
        pq.emplace(nxt, State(left, right - 1, 1, stamps + (dt + Distance(right - 1, cur) <= T[right - 1])));
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 79 ms 135160 KB Output is correct
2 Correct 80 ms 135288 KB Output is correct
3 Correct 73 ms 135160 KB Output is correct
4 Correct 75 ms 135288 KB Output is correct
5 Correct 69 ms 135164 KB Output is correct
6 Correct 83 ms 135288 KB Output is correct
7 Correct 80 ms 135288 KB Output is correct
8 Correct 71 ms 135288 KB Output is correct
9 Correct 70 ms 135288 KB Output is correct
10 Correct 70 ms 135160 KB Output is correct
11 Correct 77 ms 135164 KB Output is correct
12 Correct 70 ms 135200 KB Output is correct
13 Correct 71 ms 135160 KB Output is correct
14 Correct 70 ms 135288 KB Output is correct
15 Correct 70 ms 135288 KB Output is correct
16 Correct 79 ms 135160 KB Output is correct
17 Correct 71 ms 135288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 135160 KB Output is correct
2 Correct 80 ms 135288 KB Output is correct
3 Correct 73 ms 135160 KB Output is correct
4 Correct 75 ms 135288 KB Output is correct
5 Correct 69 ms 135164 KB Output is correct
6 Correct 83 ms 135288 KB Output is correct
7 Correct 80 ms 135288 KB Output is correct
8 Correct 71 ms 135288 KB Output is correct
9 Correct 70 ms 135288 KB Output is correct
10 Correct 70 ms 135160 KB Output is correct
11 Correct 77 ms 135164 KB Output is correct
12 Correct 70 ms 135200 KB Output is correct
13 Correct 71 ms 135160 KB Output is correct
14 Correct 70 ms 135288 KB Output is correct
15 Correct 70 ms 135288 KB Output is correct
16 Correct 79 ms 135160 KB Output is correct
17 Correct 71 ms 135288 KB Output is correct
18 Correct 75 ms 135160 KB Output is correct
19 Correct 70 ms 135160 KB Output is correct
20 Correct 70 ms 135160 KB Output is correct
21 Correct 71 ms 135288 KB Output is correct
22 Correct 69 ms 135288 KB Output is correct
23 Correct 72 ms 135288 KB Output is correct
24 Correct 70 ms 135236 KB Output is correct
25 Correct 71 ms 135160 KB Output is correct
26 Correct 79 ms 135160 KB Output is correct
27 Correct 79 ms 135288 KB Output is correct
28 Correct 70 ms 135288 KB Output is correct
29 Correct 70 ms 135160 KB Output is correct
30 Correct 71 ms 135160 KB Output is correct
31 Correct 70 ms 135160 KB Output is correct
32 Correct 76 ms 135160 KB Output is correct
33 Correct 70 ms 135260 KB Output is correct
34 Correct 72 ms 135288 KB Output is correct
35 Correct 71 ms 135288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 135160 KB Output is correct
2 Correct 80 ms 135288 KB Output is correct
3 Correct 73 ms 135160 KB Output is correct
4 Correct 75 ms 135288 KB Output is correct
5 Correct 69 ms 135164 KB Output is correct
6 Correct 83 ms 135288 KB Output is correct
7 Correct 80 ms 135288 KB Output is correct
8 Correct 71 ms 135288 KB Output is correct
9 Correct 70 ms 135288 KB Output is correct
10 Correct 70 ms 135160 KB Output is correct
11 Correct 77 ms 135164 KB Output is correct
12 Correct 70 ms 135200 KB Output is correct
13 Correct 71 ms 135160 KB Output is correct
14 Correct 70 ms 135288 KB Output is correct
15 Correct 70 ms 135288 KB Output is correct
16 Correct 79 ms 135160 KB Output is correct
17 Correct 71 ms 135288 KB Output is correct
18 Correct 829 ms 141540 KB Output is correct
19 Correct 435 ms 138472 KB Output is correct
20 Correct 168 ms 136944 KB Output is correct
21 Correct 332 ms 138472 KB Output is correct
22 Correct 572 ms 141536 KB Output is correct
23 Correct 183 ms 136948 KB Output is correct
24 Correct 100 ms 136052 KB Output is correct
25 Correct 169 ms 136816 KB Output is correct
26 Correct 93 ms 135544 KB Output is correct
27 Correct 186 ms 137024 KB Output is correct
28 Correct 98 ms 135864 KB Output is correct
29 Correct 174 ms 136052 KB Output is correct
30 Correct 95 ms 136052 KB Output is correct
31 Correct 158 ms 136052 KB Output is correct
32 Correct 106 ms 136056 KB Output is correct
33 Correct 155 ms 136052 KB Output is correct
34 Correct 80 ms 135544 KB Output is correct
35 Correct 91 ms 135868 KB Output is correct
36 Correct 81 ms 135736 KB Output is correct
37 Correct 94 ms 135736 KB Output is correct
38 Correct 95 ms 136052 KB Output is correct
39 Correct 97 ms 135736 KB Output is correct
40 Correct 85 ms 135736 KB Output is correct
41 Correct 1415 ms 147676 KB Output is correct
42 Correct 83 ms 135544 KB Output is correct
43 Correct 1311 ms 147712 KB Output is correct
44 Correct 80 ms 135608 KB Output is correct
45 Correct 1319 ms 147668 KB Output is correct
46 Correct 79 ms 135544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 135160 KB Output is correct
2 Correct 80 ms 135288 KB Output is correct
3 Correct 73 ms 135160 KB Output is correct
4 Correct 75 ms 135288 KB Output is correct
5 Correct 69 ms 135164 KB Output is correct
6 Correct 83 ms 135288 KB Output is correct
7 Correct 80 ms 135288 KB Output is correct
8 Correct 71 ms 135288 KB Output is correct
9 Correct 70 ms 135288 KB Output is correct
10 Correct 70 ms 135160 KB Output is correct
11 Correct 77 ms 135164 KB Output is correct
12 Correct 70 ms 135200 KB Output is correct
13 Correct 71 ms 135160 KB Output is correct
14 Correct 70 ms 135288 KB Output is correct
15 Correct 70 ms 135288 KB Output is correct
16 Correct 79 ms 135160 KB Output is correct
17 Correct 71 ms 135288 KB Output is correct
18 Correct 75 ms 135160 KB Output is correct
19 Correct 70 ms 135160 KB Output is correct
20 Correct 70 ms 135160 KB Output is correct
21 Correct 71 ms 135288 KB Output is correct
22 Correct 69 ms 135288 KB Output is correct
23 Correct 72 ms 135288 KB Output is correct
24 Correct 70 ms 135236 KB Output is correct
25 Correct 71 ms 135160 KB Output is correct
26 Correct 79 ms 135160 KB Output is correct
27 Correct 79 ms 135288 KB Output is correct
28 Correct 70 ms 135288 KB Output is correct
29 Correct 70 ms 135160 KB Output is correct
30 Correct 71 ms 135160 KB Output is correct
31 Correct 70 ms 135160 KB Output is correct
32 Correct 76 ms 135160 KB Output is correct
33 Correct 70 ms 135260 KB Output is correct
34 Correct 72 ms 135288 KB Output is correct
35 Correct 71 ms 135288 KB Output is correct
36 Correct 829 ms 141540 KB Output is correct
37 Correct 435 ms 138472 KB Output is correct
38 Correct 168 ms 136944 KB Output is correct
39 Correct 332 ms 138472 KB Output is correct
40 Correct 572 ms 141536 KB Output is correct
41 Correct 183 ms 136948 KB Output is correct
42 Correct 100 ms 136052 KB Output is correct
43 Correct 169 ms 136816 KB Output is correct
44 Correct 93 ms 135544 KB Output is correct
45 Correct 186 ms 137024 KB Output is correct
46 Correct 98 ms 135864 KB Output is correct
47 Correct 174 ms 136052 KB Output is correct
48 Correct 95 ms 136052 KB Output is correct
49 Correct 158 ms 136052 KB Output is correct
50 Correct 106 ms 136056 KB Output is correct
51 Correct 155 ms 136052 KB Output is correct
52 Correct 80 ms 135544 KB Output is correct
53 Correct 91 ms 135868 KB Output is correct
54 Correct 81 ms 135736 KB Output is correct
55 Correct 94 ms 135736 KB Output is correct
56 Correct 95 ms 136052 KB Output is correct
57 Correct 97 ms 135736 KB Output is correct
58 Correct 85 ms 135736 KB Output is correct
59 Correct 1415 ms 147676 KB Output is correct
60 Correct 83 ms 135544 KB Output is correct
61 Correct 1311 ms 147712 KB Output is correct
62 Correct 80 ms 135608 KB Output is correct
63 Correct 1319 ms 147668 KB Output is correct
64 Correct 79 ms 135544 KB Output is correct
65 Correct 150 ms 138472 KB Output is correct
66 Correct 156 ms 138452 KB Output is correct
67 Correct 132 ms 138476 KB Output is correct
68 Correct 122 ms 138472 KB Output is correct
69 Correct 193 ms 141544 KB Output is correct
70 Correct 270 ms 138448 KB Output is correct
71 Correct 103 ms 136944 KB Output is correct
72 Correct 266 ms 136920 KB Output is correct
73 Correct 267 ms 141540 KB Output is correct
74 Correct 244 ms 136944 KB Output is correct
75 Correct 100 ms 136964 KB Output is correct
76 Correct 1171 ms 141644 KB Output is correct
77 Correct 117 ms 136944 KB Output is correct
78 Correct 780 ms 138348 KB Output is correct
79 Correct 119 ms 138476 KB Output is correct
80 Correct 1155 ms 141536 KB Output is correct
81 Correct 101 ms 136944 KB Output is correct
82 Correct 476 ms 141540 KB Output is correct
83 Correct 111 ms 138476 KB Output is correct
84 Correct 514 ms 141540 KB Output is correct
85 Correct 564 ms 141684 KB Output is correct
86 Correct 604 ms 141560 KB Output is correct
87 Correct 122 ms 138476 KB Output is correct
88 Correct 366 ms 141540 KB Output is correct
89 Correct 102 ms 136944 KB Output is correct
90 Correct 82 ms 135592 KB Output is correct
91 Correct 362 ms 147672 KB Output is correct
92 Correct 117 ms 136944 KB Output is correct
93 Correct 80 ms 135736 KB Output is correct