Submission #721871

#TimeUsernameProblemLanguageResultExecution timeMemory
721871OttincaMUplifting Excursion (BOI22_vault)C++17
0 / 100
424 ms524288 KiB
#include <iostream> #include <vector> #include "stdio.h" using namespace std; #define int long long long long const LLINF = 8e18; int const N = 600000; int const ZER = 300000; signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #ifdef WTF freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); freopen("error.txt", "w", stderr); #endif int m, l; cin >> m >> l; int smn = 0, smf = 0; vector <int> a(2 * m + 2), x, y, z; for(int i = 1; i <= 2 * m + 1; i ++){ cin >> a[i]; int K = a[i]; while(K --){ if(i - 1 - m > 0){ x.push_back(i - 1 - m); smn += i - 1 - m; } else if(i - 1 - m < 0){ y.push_back(i - 1 - m); smf += i - 1 - m; } else { z.push_back(i - 1 - m); } } } if(l > smn || l < smf){ cout << "impossible\n"; return 0; } vector <int> dp(N, -LLINF); dp[ZER] = (int)z.size(); int mn = ZER, mx = ZER; for(int t: x){ for(int i = min(N, mx + t + 1); i >= mn; i--){ if(i - t >= 0 && dp[i - t] != -LLINF){ dp[i] = max(dp[i], dp[i - t] + 1); mn = min(mn, i); mx = max(mx, i); } } } for(int t: y){ for(int i = max(0LL, mn - t + 1); i <= mx; i ++){ if(i - t < N && dp[i - t] != -LLINF){ dp[i] = max(dp[i], dp[i - t] + 1); mn = min(mn, i); mx = max(mx, i); } } } // for(int i = 0; i < N; i ++) cout << dp[i] << " "; int ans = -LLINF; for(int i = 0; i < N; i ++){ if(i - ZER == l){ ans = dp[i]; break; } } if(ans == -LLINF){ cout << "impossible\n"; } else { cout << ans << "\n"; } return 0; }
#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...