이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
sculpture.cpp:38:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
38 | main(){
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |