Submission #1062535

# Submission time Handle Problem Language Result Execution time Memory
1062535 2024-08-17T08:22:53 Z awu Uplifting Excursion (BOI22_vault) C++14
20 / 100
925 ms 1340 KB
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
 
#define int long long
#define ll long long
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) [&](decltype(x) _x) {cerr << #x << " = " << _x << endl; return _x;}(x)
using pii =  pair<int, int>;
 
const ll inf = 1ll << 60;
// const int inf = 1 << 30;
 
template <typename T, typename U>
ostream& operator<<(ostream& out, pair<T, U> p) {
  return out << "(" << p.f << ", " << p.s << ")";
}
template <typename T, typename = decltype(begin(declval<T>()))>
typename enable_if<!is_same<T, string>::value, ostream&>::type operator<<(ostream& out, T x) {
  string dlm = "";
  out << "{";
  for(auto i : x) {
    out << dlm << i;
    dlm = ", ";
  }
  return out << "}";
}
 
const int K = 2;
const int K2 = 2;
const int K3 = 0;
 
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int m, l; cin >> m >> l;
  int* a = new int[2 * m + 1];
  a += m;
  int tot = 0;
  for(int i = -m; i <= m; i++) {
    cin >> a[i];
    tot += a[i];
    l -= a[i] * i;
  }
  l *= -1;
  if(l < 0) {
    // debug("HERE");
    l *= -1;
    reverse(a - m, a + m + 1);
  }
  // debug(l);
  int j = m;
  int ans = 0;
  while(l > m * m * K) {
    while(a[j] <= m * K3) {
      j--;
      if(j <= 0) {
        cout << "impossible" << endl;
        return 0;
      }
    }
    if(l - (a[j] - m * K3) * j > m * m * K) {
      l -= (a[j] - m * K3) * j;
      ans += (a[j] - m * K3);
      a[j] = 0;
    } else {
      int v = (l - m * m * K) / j;
      if(a[j] - v > m * K3) v++;
      l -= v * j;
      a[j] -= v;
      ans += v;
    }
  }
  vector<int> th;
  for(int i = -m; i <= m; i++) {
    if(i == 0) continue;
    for(int j = 0; j < min(a[i], m); j++) {
      th.push_back(i);
    }
  }
  random_shuffle(all(th));
  // debug(th);
  int* dp = new int[m * m * K * K2 * 2 + 1];
  dp += m * m * K * K2;
  fill(dp - m * m * K * K2, dp + m * m * K * K2 + 1, inf);
  dp[0] = 0;
  for(auto i : th) {
    if(i > 0) {
      for(int j = m * m * K * K2; j >= -m * m * K * K2; j--) {
        if(j - i >= -m * m * K * K2) {
          dp[j] = min(dp[j], dp[j - i] + 1);
        }
      }
    } else {
      for(int j = -m * m * K * K2; j <= m * m * K * K2; j++) {
        if(j - i <= m * m * K * K2) {
          dp[j] = min(dp[j], dp[j - i] + 1);
        }
      }
    }
  }
  if(dp[l] >= inf) {
    cout << "impossible" << endl;
    return 0;
  }
  cout << tot - (ans + dp[l]) << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 38 ms 604 KB Output is correct
7 Correct 10 ms 644 KB Output is correct
8 Correct 32 ms 600 KB Output is correct
9 Correct 49 ms 668 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 38 ms 604 KB Output is correct
7 Correct 10 ms 644 KB Output is correct
8 Correct 32 ms 600 KB Output is correct
9 Correct 49 ms 668 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 43 ms 600 KB Output is correct
18 Correct 11 ms 600 KB Output is correct
19 Correct 32 ms 604 KB Output is correct
20 Correct 50 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 556 ms 1284 KB Output is correct
25 Correct 135 ms 1116 KB Output is correct
26 Correct 925 ms 1340 KB Output is correct
27 Correct 756 ms 1320 KB Output is correct
28 Correct 12 ms 860 KB Output is correct
29 Correct 11 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 38 ms 604 KB Output is correct
7 Correct 10 ms 644 KB Output is correct
8 Correct 32 ms 600 KB Output is correct
9 Correct 49 ms 668 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 4 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Incorrect 4 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 38 ms 604 KB Output is correct
7 Correct 10 ms 644 KB Output is correct
8 Correct 32 ms 600 KB Output is correct
9 Correct 49 ms 668 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 43 ms 600 KB Output is correct
18 Correct 11 ms 600 KB Output is correct
19 Correct 32 ms 604 KB Output is correct
20 Correct 50 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 556 ms 1284 KB Output is correct
25 Correct 135 ms 1116 KB Output is correct
26 Correct 925 ms 1340 KB Output is correct
27 Correct 756 ms 1320 KB Output is correct
28 Correct 12 ms 860 KB Output is correct
29 Correct 11 ms 860 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Incorrect 4 ms 348 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 4 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Incorrect 4 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 452 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 38 ms 604 KB Output is correct
7 Correct 10 ms 644 KB Output is correct
8 Correct 32 ms 600 KB Output is correct
9 Correct 49 ms 668 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 43 ms 600 KB Output is correct
18 Correct 11 ms 600 KB Output is correct
19 Correct 32 ms 604 KB Output is correct
20 Correct 50 ms 600 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 556 ms 1284 KB Output is correct
25 Correct 135 ms 1116 KB Output is correct
26 Correct 925 ms 1340 KB Output is correct
27 Correct 756 ms 1320 KB Output is correct
28 Correct 12 ms 860 KB Output is correct
29 Correct 11 ms 860 KB Output is correct
30 Correct 0 ms 344 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Incorrect 4 ms 348 KB Output isn't correct
34 Halted 0 ms 0 KB -