Submission #676856

# Submission time Handle Problem Language Result Execution time Memory
676856 2023-01-01T11:17:20 Z Arnch Bali Sculptures (APIO15_sculpture) C++17
0 / 100
1 ms 212 KB
// oooo
/*
 har chi delet mikhad bebar ~
 gitar o ba khodet nabar! ~
 ;Amoo_Hasan;
*/

/*
	link:	
*/

#include<bits/stdc++.h>
//#pragma GCC optimize("O3,no-stack-protector,unroll-loops")
//#pragma GCC target("avx2,fma")

using namespace std;

typedef long long ll;
typedef long double ld;

#define Sz(x) int((x).size())
#define All(x) (x).begin(), (x).end()
#define wtf(x) cout<<#x <<" : " <<x <<endl
#define mak make_pair

//constexpr int PRI = 1000696969;
constexpr ll INF = 1e18, N = 1e6 + 10, MOD = 1e9 + 7;

int n, A, B;
ll a[N], dp[N];

bool ok(ll x) {
	ll last = 0, sum = 0, cur = 0;
	dp[0] = 0;
	for(int i = 1; i <= n; i++) {
		dp[i] = INF;
		sum = 0;
		for(int j = i; j >= 1; j--) {
			sum += a[j];
			if((sum & x) == sum) dp[i] = min(dp[i], dp[j - 1] + 1);
		}
	}	
	if(dp[n] <= B) return true;
	ll tmp = 0;
	for(int i = 60; i >= 0; i--) {
		if(!((x >> i) & 1)) {
			tmp |= (1 << i);
			continue;
		}
		dp[0] = 0;
		for(int j = 1; j <= n; j++) {
			dp[j] = INF;
			sum = 0;
			for(int k = j; k >= 1; k--) {
				sum += a[k];
				if(((sum & tmp) & x) == (sum & tmp) && !((sum >> i) & 1))
					dp[j] = min(dp[j], dp[k - 1] + 1);
			}
		}
		tmp |= (1 << i);
		if(dp[n] <= B) return true;
	}
	return false;
}	

int main() {
	ios :: sync_with_stdio(0), cin.tie(0); cout.tie(0);

	cin >>n >>A >>B;
	for(int i = 1; i <= n; i++) cin >>a[i];


	ll l = 0, r = 1e18;
	while(l < r) {
		ll mid = (l + r) >> 1;
		if(ok(mid)) r = mid;
		else l = mid + 1;
	}	

	cout<<l;

	
	return 0;
}


Compilation message

sculpture.cpp: In function 'bool ok(ll)':
sculpture.cpp:33:5: warning: unused variable 'last' [-Wunused-variable]
   33 |  ll last = 0, sum = 0, cur = 0;
      |     ^~~~
sculpture.cpp:33:24: warning: unused variable 'cur' [-Wunused-variable]
   33 |  ll last = 0, sum = 0, cur = 0;
      |                        ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -