Submission #634769

#TimeUsernameProblemLanguageResultExecution timeMemory
634769null_aweUplifting Excursion (BOI22_vault)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define ll long long int main() { int n; cin >> n; n = 2 * n + 1; ll l; cin >> l; vector<ll> arr(n); for (int i = 0; i < n; ++i) cin >> arr[i]; if (l < 0) reverse(arr.begin(), arr.end()), l = -l; for (int i = 0; i < n / 2; ++i) arr[n - 1 - i] += arr[i], l += (n / 2 - i) * arr[i], arr[i] = 0; ll sum = 0; vector<ll> count(n / 2 + 1); count[0] = arr[n / 2]; for (int i = 1; i <= n / 2; ++i) { if (arr[i + n / 2] * i + sum <= l) sum += arr[i + n / 2] * i, swap(count[i], arr[i + n / 2]); else { int take = (l - sum) / i; sum += i * take, count[i] += take, arr[i + n / 2] -= take; } } while (sum < l) { ll diff = l - sum; vector<ll> narr, ncount; int mn = INT_MAX; ll nsum = -1; for (int i = 1; i <= n / 2; ++i) { if (!arr[i + n / 2]) continue; ll sum2 = 0, cnt = 0; vector<ll> carr = arr, ccount = count; for (int j = i - 1; j > 0; --j) { while (ccount[j]) { if (i - sum2 <= diff) break; sum2 += j, ++carr[j + n / 2], --ccount[j], ++cnt; } if (i - sum2 <= diff) break; } ++ccount[i]; if (cnt >= mn || i - sum2 > diff) continue; narr = carr, ncount = ccount, mn = cnt, nsum = sum + i - sum2; } if (mn == INT_MAX) { cout << "impossible\n"; return 0; } arr = narr, count = ncount, sum = nsum; } if (sum != l) cout << "impossible\n"; else { ll ans = 0; for (ll num : count) ans += num; cout << ans << '\n'; } return 0; }

Compilation message (stderr)

vault.cpp: In function 'int main()':
vault.cpp:26:14: error: 'INT_MAX' was not declared in this scope
   26 |     int mn = INT_MAX;
      |              ^~~~~~~
vault.cpp:4:1: note: 'INT_MAX' is defined in header '<climits>'; did you forget to '#include <climits>'?
    3 | #include <algorithm>
  +++ |+#include <climits>
    4 | using namespace std;