Submission #238879

# Submission time Handle Problem Language Result Execution time Memory
238879 2020-06-13T10:50:50 Z thtsshz_bgwrswh Bali Sculptures (APIO15_sculpture) C++17
0 / 100
5 ms 512 KB
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
long long num[2005],n,a,b;
bool check(long long v){
	long long i,cnt=0;
	for(i=0;i<n;){
		long long index=i,ans=num[i];
		cnt++;
		if(ans>v)
			return 0;
		while(index+1<n&&num[index+1]+ans<=v){
			index++;
			ans+=num[index+1]; 
		}
		i=index+1;
	}
	return (cnt<=b);
}
bool check2(long long v,long long pos){
	long long i,cnt=0;
	for(i=0;i<n;){
		long long index=i,ans=num[i];
		cnt++;
		if(ans>v||((num[index+1]+ans)>>pos)&1)
			return 0;
		while(index+1<n&&num[index+1]+ans<=v&&!(((num[index+1]+ans)>>pos)&1)){
			index++;
			ans+=num[index+1]; 
		}
		i=index+1;
	}
	return (cnt<=b); 
}
int main(){
	long long i;
	scanf("%lld%lld%lld",&n,&a,&b);
	for(i=0;i<n;i++)
		scanf("%lld",&num[i]);
	for(i=0;i<45;i++)
		if(check((1<<(i+1))-1))
			break;
	long long ans=(1<<(i+1))-1;
	for(;i>=0;i--){
		if(check2(ans^(1<<i),i))
			ans^=(1<<i);
	}
	printf("%lld\n",ans);
}

Compilation message

sculpture.cpp: In function 'int main()':
sculpture.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld",&n,&a,&b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&num[i]);
   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 4 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 256 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -