제출 #42001

#제출 시각아이디문제언어결과실행 시간메모리
42001TAMREFBali Sculptures (APIO15_sculpture)C++11
100 / 100
100 ms864 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int mx = 2005; int n, A, B; ll S[mx], ans; bool dp1[105][105]; void solve1(){ ans = 0; ll cur = 0; for(int b = 41; b >= 0; b--){ ll t = cur | (1LL << b); dp1[0][0] = true; for(int i = 1; i <= n; i++){ for(int j = 1; j <= i; j++){ dp1[i][j] = false; for(int k = 0; k < i; k++){ ll ps = S[i] - S[k]; if(!(ps & t)){ dp1[i][j] |= dp1[k][j-1]; } } } } bool able = false; for(int i = A; i <= B; i++){ able |= dp1[n][i]; } if(able){ cur = t; }else{ ans |= (1LL << b); } } } int dp2[mx]; void solve2(){ ans = 0; ll cur = 0; for(int b = 41; b >= 0; b--){ ll t = cur | (1LL << b); for(int i = 1; i <= n; i++){ dp2[i] = 1e9; for(int j = 0; j < i; j++){ ll ps = S[i] - S[j]; if(!(ps & t)){ dp2[i] = min(dp2[i], dp2[j] + 1); } } } if(dp2[n] <= B){ cur = t; }else{ ans |= (1LL << b); } } } void input(){ cin >> n >> A >> B; for(int i = 1; i <= n; i++){ cin >> S[i]; S[i] += S[i-1]; } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); input(); n <= 100 ? solve1() : solve2(); cout << ans << endl; 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...