Submission #721364

#TimeUsernameProblemLanguageResultExecution timeMemory
721364gagik_2007Uplifting Excursion (BOI22_vault)C++17
5 / 100
737 ms4508 KiB
#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;*/ } if (L - mn > sum)return -MOD; 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 (stderr)

vault.cpp: In function 'int knapsack(std::vector<std::pair<int, int> >&, int)':
vault.cpp:48:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for (int i = 0; i < a.size(); i++) {
      |                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...