이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, d, t;
#define MAX 4007
int arr[MAX], dp[MAX][MAX];
int memo[MAX][MAX];
void costPrecomp(int l){;
int ans = 0;
if (arr[l] <= t) memo[l][l] = 1, ans = 1;
else memo[l][l] = 0, ans = 0;
int carry = arr[l] + 1;
for (int x = l+1; x < n; x++){
int val = min(arr[x], carry);
if (val <= t) ans++;
carry = min(carry, arr[x]);
carry += 1;
memo[l][x] = ans;
}
}
inline int cost(int l, int r){ return memo[l][r];}
main(){
cin >> n >> d >> t;
for (int x = 0; x < n; x++) cin >> arr[x];
for (int x = 0; x < n; x++) costPrecomp(x);
memset(dp, 63, sizeof(dp));
for (int x = 0; x < n; x++){
dp[x][1] = min(dp[x][1], cost(0, x));
vector<int> test;
for (int z = 1; z <= n; z++){
int bestLoc = -1;
for (int y = 0; y < x; y++){
if (dp[y][z-1] + cost(y+1, x) < dp[x][z]) dp[x][z] = dp[y][z-1] + cost(y+1, x), bestLoc = y;
}
if (bestLoc != -1) test.push_back(bestLoc);
}
//for (auto z : test) cout << z << ' ';
//cout << '\n';
vector<int> check = test; sort(check.begin(), check.end());
assert(check == test);
}
cout << dp[n-1][d+1];
}
컴파일 시 표준 에러 (stderr) 메시지
prison.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
32 | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |