답안 #791137

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791137 2023-07-23T12:48:10 Z shoryu386 Bali Sculptures (APIO15_sculpture) C++17
21 / 100
5 ms 9896 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define MAX 107

int n, mingrp, maxgrp;
int arr[MAX], dp[MAX][MAX][MAX], psum[MAX];
#define fyou LLONG_MAX/5
inline int sumarr(int a, int b){
	int sum = psum[b]; if (a != 0) sum -= psum[a-1];
	return sum;
}

int recur(int idx, int prevCut, int grpCount){

	if (idx == n-1){
		
		grpCount++; 
		if (grpCount >= mingrp && grpCount <= maxgrp) return sumarr(prevCut, n-1);
		else return fyou;
	}

	if (dp[idx][prevCut][grpCount] != -1) return dp[idx][prevCut][grpCount];
	int ans = 0;
	
	//choose cut or no cut
	int a = recur(idx+1, prevCut, grpCount);
	int b = recur(idx+1, idx+1, grpCount+1);
	if (a == fyou && b == fyou) ans = a;
	else if (a == fyou) ans = b;
	else if (b == fyou) ans = a;
	else ans = min(a, b | sumarr(prevCut, idx));
	
	return dp[idx][prevCut][grpCount] = ans;
}

main(){
	cin >> n >> mingrp >> maxgrp;
	
	for (int x = 0; x < n; x++){
		cin >> arr[x];
	}
	
	psum[0] = arr[0]; for (int x = 1; x < n; x++) psum[x] = psum[x-1] + arr[x];
	
	memset(dp, -1, sizeof(dp));
	assert(recur(0, 0, 0) != fyou);
	cout << recur(0, 0, 0);
}

Compilation message

sculpture.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   38 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9812 KB Output is correct
2 Correct 3 ms 9784 KB Output is correct
3 Correct 4 ms 9812 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9812 KB Output is correct
6 Correct 4 ms 9812 KB Output is correct
7 Correct 4 ms 9812 KB Output is correct
8 Correct 4 ms 9812 KB Output is correct
9 Correct 4 ms 9812 KB Output is correct
10 Correct 4 ms 9780 KB Output is correct
11 Correct 3 ms 9812 KB Output is correct
12 Correct 4 ms 9812 KB Output is correct
13 Correct 4 ms 9780 KB Output is correct
14 Incorrect 4 ms 9812 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9812 KB Output is correct
2 Correct 4 ms 9792 KB Output is correct
3 Correct 4 ms 9812 KB Output is correct
4 Correct 4 ms 9812 KB Output is correct
5 Correct 4 ms 9812 KB Output is correct
6 Correct 5 ms 9812 KB Output is correct
7 Correct 4 ms 9812 KB Output is correct
8 Correct 4 ms 9812 KB Output is correct
9 Correct 4 ms 9812 KB Output is correct
10 Correct 4 ms 9812 KB Output is correct
11 Correct 4 ms 9812 KB Output is correct
12 Correct 4 ms 9812 KB Output is correct
13 Correct 4 ms 9812 KB Output is correct
14 Incorrect 4 ms 9812 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9812 KB Output is correct
2 Correct 4 ms 9812 KB Output is correct
3 Correct 4 ms 9812 KB Output is correct
4 Correct 4 ms 9812 KB Output is correct
5 Correct 4 ms 9832 KB Output is correct
6 Correct 4 ms 9812 KB Output is correct
7 Correct 4 ms 9812 KB Output is correct
8 Correct 4 ms 9812 KB Output is correct
9 Correct 4 ms 9812 KB Output is correct
10 Correct 4 ms 9812 KB Output is correct
11 Correct 4 ms 9812 KB Output is correct
12 Correct 4 ms 9812 KB Output is correct
13 Correct 4 ms 9812 KB Output is correct
14 Correct 4 ms 9812 KB Output is correct
15 Correct 4 ms 9784 KB Output is correct
16 Correct 4 ms 9780 KB Output is correct
17 Correct 4 ms 9812 KB Output is correct
18 Correct 4 ms 9780 KB Output is correct
19 Correct 4 ms 9812 KB Output is correct
20 Correct 4 ms 9780 KB Output is correct
21 Correct 4 ms 9812 KB Output is correct
22 Correct 4 ms 9812 KB Output is correct
23 Correct 4 ms 9812 KB Output is correct
24 Correct 4 ms 9812 KB Output is correct
25 Correct 4 ms 9780 KB Output is correct
26 Correct 4 ms 9812 KB Output is correct
27 Correct 5 ms 9812 KB Output is correct
28 Correct 5 ms 9896 KB Output is correct
29 Correct 5 ms 9812 KB Output is correct
30 Correct 5 ms 9812 KB Output is correct
31 Correct 5 ms 9812 KB Output is correct
32 Correct 5 ms 9812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9812 KB Output is correct
2 Correct 4 ms 9812 KB Output is correct
3 Correct 3 ms 9812 KB Output is correct
4 Correct 4 ms 9840 KB Output is correct
5 Correct 4 ms 9812 KB Output is correct
6 Correct 4 ms 9784 KB Output is correct
7 Correct 4 ms 9812 KB Output is correct
8 Correct 4 ms 9776 KB Output is correct
9 Correct 4 ms 9812 KB Output is correct
10 Correct 5 ms 9812 KB Output is correct
11 Correct 4 ms 9784 KB Output is correct
12 Correct 3 ms 9812 KB Output is correct
13 Correct 4 ms 9812 KB Output is correct
14 Incorrect 4 ms 9780 KB Output isn't correct
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 9812 KB Output is correct
2 Correct 4 ms 9812 KB Output is correct
3 Correct 4 ms 9812 KB Output is correct
4 Correct 4 ms 9812 KB Output is correct
5 Correct 4 ms 9812 KB Output is correct
6 Correct 4 ms 9812 KB Output is correct
7 Correct 4 ms 9776 KB Output is correct
8 Correct 4 ms 9812 KB Output is correct
9 Correct 4 ms 9812 KB Output is correct
10 Correct 4 ms 9784 KB Output is correct
11 Correct 4 ms 9812 KB Output is correct
12 Correct 4 ms 9812 KB Output is correct
13 Correct 3 ms 9812 KB Output is correct
14 Correct 4 ms 9812 KB Output is correct
15 Correct 4 ms 9812 KB Output is correct
16 Correct 5 ms 9812 KB Output is correct
17 Correct 4 ms 9812 KB Output is correct
18 Incorrect 4 ms 9812 KB Output isn't correct
19 Halted 0 ms 0 KB -