Submission #411860

#TimeUsernameProblemLanguageResultExecution timeMemory
411860KarliverBali Sculptures (APIO15_sculpture)C++14
100 / 100
161 ms376 KiB
	
 #include <bits/stdc++.h>
 
 #define FIXED_FLOAT(x)  std::fixed <<std::setprecision(20) << (x)
 #define all(v) (v).begin(), (v).end()
 using namespace  std;
 #define forn(i,n) for (int i = 0; i < (n); ++i)
 #define rforn(i, n) for(int i = (n) - 1;i >= 0;--i)
 using ll = long long;
 int mod = (ll)1e9 + 7;
 #define PI acos(-1)
 typedef pair<int, int> pairs;
 
 const int INF = 1e9 + 1;
 const int N = 2e5 + 100;
 const double eps = 1e-7;
 
 template <class T> using V = vector<T>;  // from yosupo 
 template <class T> using VV = V<V<T>>;  // from yosupo
 
 template <typename XPAX>
 void ckma(XPAX &x, XPAX y) {
     x = (x < y ? y : x);
 }
 template <typename XPAX>
 void ckmi(XPAX &x, XPAX y) {
     x = (x > y ? y : x);
 }
 int n;
 int A, B;
 int a[N];
 
 void __print(int x) {cerr << x;}
 void __print(long x) {cerr << x;}
 void __print(long long x) {cerr << x;}
 void __print(unsigned x) {cerr << x;}
 void __print(unsigned long x) {cerr << x;}
 void __print(unsigned long long x) {cerr << x;}
 void __print(float x) {cerr << x;}
 void __print(double x) {cerr << x;}
 void __print(long double x) {cerr << x;}
 void __print(char x) {cerr << '\'' << x << '\'';}
 void __print(const char *x) {cerr << '\"' << x << '\"';}
 void __print(const string &x) {cerr << '\"' << x << '\"';}
 void __print(bool x) {cerr << (x ? "true" : "false");}
 
 template<typename T, typename V>
 void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
 template<typename T>
 void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
 void _print() {cerr << "]\n";}
 template <typename T, typename... V>
 void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
 #define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

 void solve() {
 
 	
 	cin >> n >> A >> B;
 	forn(i, n)cin >> a[i];
 	
 	auto issok = [&](ll bit, ll mask, ll sum) {
 		mask >>= bit;
 		sum >>= bit;
 		return (mask | sum) == mask;
 	};

 	auto construct1 = [&](ll mask, ll bit) {
 		
 		V<int> dp(n + 1, INF);
 		dp[0] = 0;
 		forn(i, n) {
 			if(dp[i] == INF)continue;
 			ll tot =0;
 			for(int j = i;j < n;++j) {
 				tot += a[j];
 				if(issok(bit, mask, tot))
 					ckmi(dp[j + 1], dp[i] + 1);
 			}
 		}


 		return dp[n] <= B;
 	};



 	auto construct2 = [&](ll mask, ll bit) {
 		VV<int> dp(n + 1, V<int>(n + 1, 0));

 		dp[0][0] = 1;
 		forn(i, n) forn(j, n) {
 			if(!dp[i][j])continue;
 			ll tot =0 ;
 			for(int t = i;t < n;++t) {
 				tot += a[t];
 				if(issok(bit, mask, tot))
 					dp[t + 1][j + 1] = 1;
 			}
 		}

 		for(int i = A;i <= B;++i) if(dp[n][i])return true;

 		return false;
 	};

 	ll ans = 0;

 	for(ll i = 50;i >= 0;--i) {
 		
 		if(A == 1) {	
 			if(!construct1(ans, i)) ans |= 1ll << i;
 		}
 		else  {
 			if(!construct2(ans, i))ans |= 1ll << i;
 		}

 	}
 	cout << ans << '\n';


 
 }
 void test_case() {
     int t;
     cin >> t;
     forn(p, t) {
 
         //cout << "Case #" << p + 1 << ": ";
         solve();
     }
 }
 int main() {
 
     ios::sync_with_stdio(false);
     cin.tie(nullptr);
     cout.tie(nullptr);
 
     solve();
 
 }
  
#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...