Submission #319731

#TimeUsernameProblemLanguageResultExecution timeMemory
319731TeaTimeBali Sculptures (APIO15_sculpture)C++17
100 / 100
130 ms508 KiB
#include<iostream> #include<vector> #include <bitset> #include <algorithm> using namespace std; typedef long long ll; typedef long double ld; #define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); const ll SZ = 3000, INF = 1e9; vector<ll> vec; ll n, a, b; ll dp[SZ]; bitset<SZ> dp2[SZ]; ll sol(bool fl) { ll curMsk = (1ll << 45) - 1; for (ll bt = 44; bt >= 0; bt--) { ll msk = curMsk ^ (1ll << bt); bool k = 0; if (!fl) { for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) dp2[i][j] = 0; } dp2[0][0] = 1; for (int i = 0; i < n; i++) { ll s = 0; for (int j = i; j >= 0; j--) { s += vec[j]; if ((msk | s) == msk) { dp2[i + 1] |= (dp2[j] << 1); } } } for (int i = a; i <= b; i++) { if (dp2[n][i]) { k = 1; } } } else { for (int i = 0; i <= n; i++) dp[i] = INF; dp[0] = 0; for (int i = 0; i < n; i++) { ll s = 0; for (int j = i; j >= 0; j--) { s += vec[j]; if ((msk | s) == msk) { dp[i + 1] = min(dp[i + 1], dp[j] + 1); } } } if (dp[n] <= b) k = 1; } if (k) { curMsk = msk; } } return curMsk; } int main() { fastInp; cin >> n >> a >> b; vec.resize(n); for (auto &cur : vec) cin >> cur; if (a == 1) { cout << sol(1); } else { cout << sol(0); } 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...