제출 #918330

#제출 시각아이디문제언어결과실행 시간메모리
918330vjudge1Bali Sculptures (APIO15_sculpture)C++17
100 / 100
95 ms4008 KiB
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // using namespace __gnu_pbds; using namespace std; //----------------------- // #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define ll long long #define ull unsigned long long #define pb push_back #define pf push_front #define mp make_pair #define mem(f,x) memset(f, x, sizeof(f)) #define __lcm(a, b) (1ll * a * b) / __gcd(a, b) #define bit(mask, i) ((mask >> i) & 1) #define pii pair<int, int> #define pll pair<ll, ll> #define el '\n' #define F first #define S second #define io(x) freopen(x".inp","r",stdin),freopen(x".out","w",stdout) //----------------------- const ll INF = 1e18; const int MOD = 1e9 + 7; const int MULTI = 0; const int dx[4] = {0, 0, 1, -1}; //R L D U const int dy[4] = {1, -1, 0, 0}; //-----AUTHOR trvhung VNG High School for Gifted Student----- const int LOG = 40; const int maxn = 2e3 + 5; int n, A, B, a[maxn]; bool ok(ll mask, ll prev, ll pos) { ll temp = (mask >> pos << pos) | prev; return temp == prev; } namespace onetwo { ll dp[maxn][maxn], pref[maxn], sum; map<ll, set<ll> > v[maxn]; bool check() { return n <= 50; } void solve() { for (int i = 1; i <= n; ++i) pref[i] = pref[i - 1] + a[i]; sum = 0; for (int i = 1; i <= n; ++i) { sum += a[i]; dp[i][1] = sum; v[i][1].insert(dp[i][1]); } for (int i = 1; i <= n; ++i) for (int j = 1; j <= min(i, B); ++j) { if (j == 1) continue; dp[i][j] = INF; sum = a[i]; for (int k = i - 1; k >= j - 1; --k) { for (auto x: v[k][j - 1]) { dp[i][j] = min(dp[i][j], x | sum); v[i][j].insert(x | sum); } sum += a[k]; } } ll res = INF; for (int i = A; i <= B; ++i) res = min(res, dp[n][i]); cout << res; } } namespace threefour { bool check() { return n <= 100; } const int maxn = 1e2 + 5; bool dp[maxn][maxn]; ll prev = 0; void solve() { for (int j = LOG; j >= 0; --j) { mem(dp, false); dp[0][0] = true; for (int i = 1; i <= n; ++i) for (int k = 1; k <= i; ++k) { ll sum = 0; for (int z = i; z >= 1; --z) { sum += a[z]; if (ok(sum, prev, j)) dp[i][k] |= dp[z - 1][k - 1]; } } bool check = false; for (int i = A; i <= B; ++i) if (dp[n][i]) check = true; if (!check) prev += (1ll << j); } cout << prev; } } namespace five { ll prev = 0, dp[maxn]; void solve() { for (int j = LOG; j >= 0; --j) { for (int i1 = 1; i1 <= n; ++i1) dp[i1] = INF; dp[0] = 0; for (int i = 1; i <= n; ++i) { ll sum = 0; for (int z = i; z >= 1; --z) { sum += a[z]; if (ok(sum, prev, j)) dp[i] = min(dp[i], dp[z - 1] + 1); } } if (dp[n] > B) prev += (1ll << j); } cout << prev; } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> A >> B; for (int i = 1; i <= n; ++i) cin >> a[i]; if (onetwo::check()) return onetwo::solve(), 0; if (threefour::check()) return threefour::solve(), 0; five::solve(); 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...