# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1101098 | 2024-10-15T13:51:01 Z | Zero_OP | Bali Sculptures (APIO15_sculpture) | C++14 | 1 ms | 608 KB |
#include <bits/stdc++.h> using namespace std; #define rep(i, l, r) for(int i = (l), _r = (r); i < _r; ++i) #define FOR(i, l, r) for(int i = (l), _r = (r); i <= _r; ++i) #define ROF(i, r, l) for(int i = (r), _l = (l); i >= _l; --i) #define all(v) begin(v), end(v) #define compact(v) v.erase(unique(all(v)), end(v)) #define sz(v) (int)v.size() #define dbg(x) "[" #x " = " << (x) << "]" template<typename T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; } template<typename T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; } using ll = long long; using ld = long double; mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template<typename T> T random_int(T l, T r){ return uniform_int_distribution<T>(l, r)(rng); } template<typename T> T random_real(T l, T r){ return uniform_real_distribution<T>(l, r)(rng); } const int MAX = 2e3 + 5; int n, A, B, a[MAX]; ll pref[MAX]; ll sum(int l, int r){ return pref[r] - pref[l - 1]; } namespace subtask4{ int dp[105][105]; void solve(){ ll ans = (1LL << 60) - 1; for(int B = 59; B >= 0; --B){ ans ^= (1LL << B); //try to erase largest bit memset(dp, false, sizeof(dp)); dp[0][0] = true; for(int s = 1; s <= B; ++s){ for(int i = 1; i <= n; ++i){ for(int j = 1; j <= i; ++j){ if((sum(j, i) | ans) == ans){ dp[s][i] |= dp[s - 1][j - 1]; } } } } bool ok = false; for(int s = A; s <= B; ++s){ ok |= dp[s][n]; } if(!ok) ans ^= (1LL << B); //cant } cout << ans << '\n'; } } namespace subtask5{ int dp[MAX]; void solve(){ ll ans = (1LL << 60) - 1; for(int B = 59; B >= 0; --B){ ans ^= (1LL << B); //try to erase largest bit memset(dp, 0x3f, sizeof(dp)); dp[0] = 0; for(int i = 1; i <= n; ++i){ for(int j = 1; j <= i; ++j){ if((sum(j, i)| ans) == ans){ dp[i] = min(dp[i], dp[j - 1] + 1); } } } if(dp[n] > B) ans ^= (1LL << B); //cant } cout << ans << '\n'; } } void testcase(){ cin >> n >> A >> B; FOR(i, 1, n) cin >> a[i], pref[i] = pref[i - 1] + a[i]; if(n <= 100) subtask4::solve(); else subtask5::solve(); } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); #define filename "task" if(fopen(filename".inp", "r")){ freopen(filename".inp", "r", stdin); freopen(filename".out", "w", stdout); } int T = 1; //cin >> T; while(T--) testcase(); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Incorrect | 1 ms | 340 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Incorrect | 1 ms | 352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Incorrect | 1 ms | 608 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Incorrect | 1 ms | 352 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 352 KB | Output is correct |
2 | Incorrect | 1 ms | 348 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |