Submission #923093

#TimeUsernameProblemLanguageResultExecution timeMemory
923093quanlt206Bali Sculptures (APIO15_sculpture)C++17
100 / 100
460 ms708 KiB
#include<bits/stdc++.h> #define X first #define Y second #define all(x) begin(x), end(x) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, b, a) for(int i = (b); i >= (a); i--) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define mxx max_element #define mnn min_element #define SQR(x) (1LL * (x) * (x)) #define MASK(i) (1LL << (i)) #define Point Vector #define left Left #define right Right #define div Div using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; typedef pair<ll, int> pli; typedef pair<ll, pii> plii; template<class A, class B> bool maximize(A& x, B y) { if (x < y) return x = y, true; else return false; } template<class A, class B> bool minimize(A& x, B y) { if (x > y) return x = y, true; else return false; } /* END OF TEMPLATE */ const int N = 2e3 + 7; int n, a[N], A, B; ll pre[N]; ll getSum(int i, int j) { return pre[j] - pre[i - 1]; } namespace sub1 { const int N = 107; const int M = 45; bool f[N][N]; ll solve(int m) { ll res = 0; FORD(x, M, 0) { FOR(i, 0, n) FOR(j, 0, m + 1) f[i][j] = false; f[0][0] = true; REP(i, 0, n) FOR(j, 0, m) if (f[i][j]) { FOR(k, i + 1, n) { ll sum = getSum(i + 1, k); if (((res | sum) <= res + MASK(x) - 1)) { f[k][j + 1] = true; } } } if (f[n][m]) continue; res^=MASK(x); } return res; } void Process() { ll res = 1e18; FOR(x, A, B) minimize(res, solve(x)); cout<<res; } } namespace sub2 { const int N = 2007; const int M = 45; int f[N]; ll solve() { ll res = 0; FORD(x, M, 0) { FOR(i, 0, n) f[i] = n + 3; f[0] = 0; REP(i, 0, n) if (f[i] != n + 3) { FOR(k, i + 1, n) { ll sum = getSum(i + 1, k); if (((res | sum) <= res + MASK(x) - 1)) minimize(f[k], f[i] + 1); } } if (f[n] <= B) continue; res^=MASK(x); } return res; } void Process() { cout<<solve(); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>A>>B; FOR(i, 1, n) { cin>>a[i]; pre[i] = pre[i - 1] + a[i]; } if (n <= 100) { sub1::Process(); return 0; } sub2::Process(); 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...