Submission #604616

# Submission time Handle Problem Language Result Execution time Memory
604616 2022-07-25T08:11:11 Z Plurm Uplifting Excursion (BOI22_vault) C++11
5 / 100
5000 ms 12456 KB
#include <bits/stdc++.h>
using namespace std;

template <typename T> class negarr {
private:
  T data[505000 * 2 + 1];

public:
  negarr() { memset(data, 0, sizeof(data)); }
  void reset() { fill(data, data + 505000 * 2 + 1, -1000000000); }
  inline T &operator[](int i) { return data[i + 505000]; }
};

class pstate {
public:
  int x, y;
  pstate(int x, int y) : x(x), y(y) {}
  friend bool operator<(const pstate &a, const pstate &b) {
    return a.x + a.y < b.x + b.y;
  }
};
class nstate {
public:
  int x, y;
  nstate(int x, int y) : x(x), y(y) {}
  friend bool operator<(const nstate &a, const nstate &b) {
    return a.y - a.x < b.y - b.x;
  }
};
negarr<int> a, knapsack;
int main() {
  int m;
  long long l;
  cin >> m >> l;
  const int BOUND = m * (m + 1) / 2 * 100;
  if (l > BOUND || l < -BOUND) {
    printf("impossible\n");
    return 0;
  }
  knapsack.reset();
  knapsack[0] = 0;
  for (int i = -m; i <= m; i++) {
    cin >> a[i];
    negarr<int> tmp;
    tmp.reset();
    if (i == 0) {
      for (int id = -BOUND; id <= BOUND; id++) {
        knapsack[id] += a[i];
      }
    } else {
      if (i > 0) {
        vector<priority_queue<nstate>> pq(i);
        for (int id = -BOUND; id <= BOUND; id++) {
          int mod = id % i;
          if (mod < 0)
            mod += i;
          int xx = (id + BOUND) / i;
          while (!pq[mod].empty() && xx - pq[mod].top().x > a[i])
            pq[mod].pop();
          while (!pq[mod].empty() && pq[mod].top() < nstate(xx, knapsack[id]))
            pq[mod].pop();
          pq[mod].push({xx, knapsack[id]});
          if (!pq[mod].empty()) {
            nstate t = pq[mod].top();
            tmp[id] = max(tmp[id], t.y - t.x + xx);
          }
        }
      } else if (i < 0) {
        vector<priority_queue<pstate>> pq(-i);
        for (int id = BOUND; id >= -BOUND; id--) {
          int mod = id % (-i);
          if (mod < 0)
            mod += (-i);
          int xx = (id + BOUND) / (-i);
          while (!pq[mod].empty() && pq[mod].top().x - xx > a[i])
            pq[mod].pop();
          while (!pq[mod].empty() && pq[mod].top() < pstate(xx, knapsack[id]))
            pq[mod].pop();
          pq[mod].push({xx, knapsack[id]});
          if (!pq[mod].empty()) {
            pstate t = pq[mod].top();
            knapsack[id] = max(knapsack[id], t.y + t.x - xx);
          }
        }
      }
      for (int id = -BOUND; id <= BOUND; id++) {
        knapsack[id] = max(knapsack[id], tmp[id]);
      }
    }
  }
  if (knapsack[l] >= 0)
    printf("%d\n", knapsack[l]);
  else
    printf("impossible\n");
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12116 KB Output is correct
2 Correct 12 ms 12152 KB Output is correct
3 Correct 9 ms 12116 KB Output is correct
4 Correct 31 ms 12148 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 1201 ms 12200 KB Output is correct
7 Correct 880 ms 12200 KB Output is correct
8 Correct 1221 ms 12200 KB Output is correct
9 Correct 1341 ms 12336 KB Output is correct
10 Correct 667 ms 12264 KB Output is correct
11 Correct 668 ms 12152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12116 KB Output is correct
2 Correct 12 ms 12152 KB Output is correct
3 Correct 9 ms 12116 KB Output is correct
4 Correct 31 ms 12148 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 1201 ms 12200 KB Output is correct
7 Correct 880 ms 12200 KB Output is correct
8 Correct 1221 ms 12200 KB Output is correct
9 Correct 1341 ms 12336 KB Output is correct
10 Correct 667 ms 12264 KB Output is correct
11 Correct 668 ms 12152 KB Output is correct
12 Correct 11 ms 12076 KB Output is correct
13 Correct 12 ms 12104 KB Output is correct
14 Correct 9 ms 12116 KB Output is correct
15 Correct 28 ms 12156 KB Output is correct
16 Correct 8 ms 12152 KB Output is correct
17 Correct 1199 ms 12200 KB Output is correct
18 Correct 881 ms 12208 KB Output is correct
19 Correct 1264 ms 12204 KB Output is correct
20 Correct 1339 ms 12216 KB Output is correct
21 Correct 679 ms 12276 KB Output is correct
22 Correct 674 ms 12160 KB Output is correct
23 Correct 6 ms 12116 KB Output is correct
24 Execution timed out 5050 ms 12456 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 12152 KB Output is correct
2 Incorrect 6 ms 12132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 12152 KB Output is correct
2 Incorrect 6 ms 12132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 12152 KB Output is correct
2 Incorrect 6 ms 12132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12116 KB Output is correct
2 Correct 12 ms 12152 KB Output is correct
3 Correct 9 ms 12116 KB Output is correct
4 Correct 31 ms 12148 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 1201 ms 12200 KB Output is correct
7 Correct 880 ms 12200 KB Output is correct
8 Correct 1221 ms 12200 KB Output is correct
9 Correct 1341 ms 12336 KB Output is correct
10 Correct 667 ms 12264 KB Output is correct
11 Correct 668 ms 12152 KB Output is correct
12 Correct 28 ms 12152 KB Output is correct
13 Incorrect 6 ms 12132 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 12152 KB Output is correct
2 Incorrect 6 ms 12132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12116 KB Output is correct
2 Correct 12 ms 12152 KB Output is correct
3 Correct 9 ms 12116 KB Output is correct
4 Correct 31 ms 12148 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 1201 ms 12200 KB Output is correct
7 Correct 880 ms 12200 KB Output is correct
8 Correct 1221 ms 12200 KB Output is correct
9 Correct 1341 ms 12336 KB Output is correct
10 Correct 667 ms 12264 KB Output is correct
11 Correct 668 ms 12152 KB Output is correct
12 Correct 11 ms 12076 KB Output is correct
13 Correct 12 ms 12104 KB Output is correct
14 Correct 9 ms 12116 KB Output is correct
15 Correct 28 ms 12156 KB Output is correct
16 Correct 8 ms 12152 KB Output is correct
17 Correct 1199 ms 12200 KB Output is correct
18 Correct 881 ms 12208 KB Output is correct
19 Correct 1264 ms 12204 KB Output is correct
20 Correct 1339 ms 12216 KB Output is correct
21 Correct 679 ms 12276 KB Output is correct
22 Correct 674 ms 12160 KB Output is correct
23 Correct 6 ms 12116 KB Output is correct
24 Execution timed out 5050 ms 12456 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 12152 KB Output is correct
2 Incorrect 6 ms 12132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 12116 KB Output is correct
2 Correct 12 ms 12152 KB Output is correct
3 Correct 9 ms 12116 KB Output is correct
4 Correct 31 ms 12148 KB Output is correct
5 Correct 6 ms 12116 KB Output is correct
6 Correct 1201 ms 12200 KB Output is correct
7 Correct 880 ms 12200 KB Output is correct
8 Correct 1221 ms 12200 KB Output is correct
9 Correct 1341 ms 12336 KB Output is correct
10 Correct 667 ms 12264 KB Output is correct
11 Correct 668 ms 12152 KB Output is correct
12 Correct 11 ms 12076 KB Output is correct
13 Correct 12 ms 12104 KB Output is correct
14 Correct 9 ms 12116 KB Output is correct
15 Correct 28 ms 12156 KB Output is correct
16 Correct 8 ms 12152 KB Output is correct
17 Correct 1199 ms 12200 KB Output is correct
18 Correct 881 ms 12208 KB Output is correct
19 Correct 1264 ms 12204 KB Output is correct
20 Correct 1339 ms 12216 KB Output is correct
21 Correct 679 ms 12276 KB Output is correct
22 Correct 674 ms 12160 KB Output is correct
23 Correct 6 ms 12116 KB Output is correct
24 Execution timed out 5050 ms 12456 KB Time limit exceeded
25 Halted 0 ms 0 KB -