제출 #23427

#제출 시각아이디문제언어결과실행 시간메모리
2342714kgBali Sculptures (APIO15_sculpture)C++11
100 / 100
283 ms36356 KiB
#include <stdio.h>
#define N 2002
#define INF 999999999
#define min2(x,y) (x<y?x:y)
#define max2(x,y) (x>y?x:y)

int n, L, R, nn;
bool out[51], check[N][N];
long long p[51], in[N], s[N][N];

int main()
{
	int num, temp1[N], temp2[N];
	long long sum, tot=0;

	scanf("%d %d %d", &n, &L, &R);
	for (int i = 1; i <= n; i++) scanf("%lld", &in[i]);
	p[0] = 1;
	for (int i = 1; i <= 50; i++) p[i] = p[i - 1] * 2;
	for (int i = 1; i <= n; i++) for (int j = i; j <= n; j++) s[i][j] = s[i][j - 1] + in[j];
	if (s[1][n] == 0) { printf("0"); return 0; }

	for (int i = 49; i >= 0; i--)
	{
		num = 1, sum = 0;
		for (int j = 1; j <= n; j++)
		{
			sum += in[j];
			if (sum >= p[i + 1]) sum = in[j], num++;
			if (sum >= p[i + 1]) { num = INF; break; }
		}
		if (num > R) { nn = i + 1; break; }
	} out[nn] = true;

	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++) if (s[i][j] < p[nn + 1]) check[i][j] = true;

	for (int i = nn - 1; i >= 0; i--)
	{
		temp1[1] = 0, temp2[1] = 0;
		for (int j = 2; j <= n + 1; j++) temp1[j] = INF, temp2[j] = -INF;
		
		for (int j = 1; j <= n; j++)
			for (int t = j; t <= n; t++) if (check[j][t] && (s[j][t] & p[i]) == 0)
				temp1[t + 1] = min2(temp1[t + 1], temp1[j] + 1), temp2[t + 1] = max2(temp2[t + 1], temp2[j] + 1);

		if (temp1[n + 1] != INF && L <= temp2[n + 1] && temp1[n + 1] <= R)
		{
			for (int j = 1; j <= n; j++)
				for (int t = j; t <= n; t++) if (s[j][t] & p[i]) check[j][t] = false;
		}
		else out[i] = true;
	}
	for (int i = nn; i >= 0; i--)
		if (out[i]) tot += p[i];
	printf("%lld", tot);
}

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

sculpture.cpp: In function 'int main()':
sculpture.cpp:16:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d", &n, &L, &R);
                               ^
sculpture.cpp:17:52: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf("%lld", &in[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...