제출 #102012

#제출 시각아이디문제언어결과실행 시간메모리
102012Nicholas_PatrickBali Sculptures (APIO15_sculpture)C++17
50 / 100
98 ms640 KiB
#include <bits/stdc++.h>
using namespace std;

int n, a, b;
vector <long long> y, psy;
vector <int> memo;
int checkPossibility(long long x, long long toDeduct=0, int checkFrom=0){
	if(checkFrom==n)
		return 0;
	if(memo[checkFrom])
		return memo[checkFrom];
	int ret=n;
	for(int i = checkFrom;i < n;i ++){
		if(((psy[i]-toDeduct)|x)==x)
			ret=min(ret, checkPossibility(x, psy[i], i+1));
		if(psy[i]-toDeduct>x)
			break;
	}
	return memo[checkFrom]=ret+1;
}
int main(){
	scanf("%d %d %d", &n, &a, &b);
	y.resize(n);
	psy.resize(n);
	for(int i = 0;i < n;i ++)
		scanf("%lld", &y[i]);
	psy[0]=y[0];
	for(int i = 1;i < n;i ++)
		psy[i]=psy[i-1]+y[i];
	if(a==1){
		long long check=0x1FFFFFFFFFF;
		for(int i = 40;i >= 0;i --){
			memo.clear();
			memo.resize(n, 0);
			if(checkPossibility(check-(1ll<<i))<=b){
				check-=1ll<<i;
			}
		}
		printf("%lld\n", check);
	}else{

	}
}
/*
20 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

*/

컴파일 시 표준 에러 (stderr) 메시지

sculpture.cpp: In function 'int main()':
sculpture.cpp:22:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &a, &b);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sculpture.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &y[i]);
   ~~~~~^~~~~~~~~~~~~~~
#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...