# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
721363 | 2023-04-10T18:44:23 Z | gagik_2007 | Uplifting Excursion (BOI22_vault) | C++17 | 42 ms | 972 KB |
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <chrono> #include <ctime> #include <set> #include <map> #include <stack> #include <queue> #include <deque> #include <limits> #include <iomanip> #include <unordered_set> #include <unordered_map> #include <fstream> #include <functional> #include <random> #include <cassert> using namespace std; typedef long long ll; typedef long double ld; #define ff first #define ss second ll ttt; const ll INF = 1e18; const ll MOD = 1e9 + 7; const ll N = 100007; const ll LG = 31; ll n, m, k; ll c[N]; int knapsack(vector<pair<int, int>>& a, int L) { ll sum = 0; ll mn = 0; for (auto x : a) { //cout << x.ff << " " << x.ss << endl; sum += abs(x.ff); mn += min(0, x.ff); } //cout << endl << endl; vector<int>dp(sum + 1, -MOD); dp[-mn] = 0; for (int i = 0; i < a.size(); i++) { if (a[i].ff >= 0) { for (int j = sum; j - a[i].ff >= 0; j--) { dp[j] = max(dp[j], dp[j - a[i].ff] + a[i].ss); } } else { for (int j = 0; j - a[i].ff <= sum; j++) { dp[j] = max(dp[j], dp[j - a[i].ff] + a[i].ss); } } /*for (int j = 0; j <= sum; j++) { cout << j + mn << ": " << dp[j] << "\n"; } cout << endl;*/ } return dp[L - mn]; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; vector<pair<int, int>>a; ll cur = -n; for (int i = 0; i <= 2 * n; i++, cur++) { cin >> c[i]; for (int j = LG; j >= 0; j--) { if (c[i] & (1ll << j)) { for (int p = j - 1; p >= 0; p--) { a.push_back({ cur * (1ll << p),(1ll << p) }); } ll rem = c[i] - (1ll << j) + 1; a.push_back({ cur * rem,rem }); break; } } } ll res = knapsack(a, k); if (res >= 0) { cout << res << endl; } else cout << "impossible\n"; } /// ---- - -------- ------ -------- -- - - - /// Just a reminder. Ubuntu password is I O I /// ---- - -------- ------ -------- -- - - -
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Runtime error | 42 ms | 972 KB | Execution killed with signal 11 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Runtime error | 42 ms | 972 KB | Execution killed with signal 11 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Runtime error | 3 ms | 596 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Runtime error | 3 ms | 596 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Runtime error | 3 ms | 596 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Runtime error | 42 ms | 972 KB | Execution killed with signal 11 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Runtime error | 3 ms | 596 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Runtime error | 42 ms | 972 KB | Execution killed with signal 11 |
6 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 336 KB | Output is correct |
2 | Runtime error | 3 ms | 596 KB | Execution killed with signal 6 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Runtime error | 42 ms | 972 KB | Execution killed with signal 11 |
6 | Halted | 0 ms | 0 KB | - |