이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=4e3+5;
int n, d, T, dp[nx][nx], c[nx][nx], t[nx], lst;
void solve(int l, int r, int layer, int optl, int optr)
{
if (r<l) return;
int md=(l+r)/2;
//cout<<"debug "<<md<<' '<<optl<<' '<<optr<<'\n';
pair<int, int> mn={INT_MAX, 0};
for (int i=optl; i<=min(optr, md); i++) mn=min(mn, {dp[layer-1][i-1]+c[i][md], i});
//cout<<"md "<<md<<' '<<mn.first<<' '<<mn.second<<'\n';
dp[layer][md]=mn.first;
solve(l, md-1, layer, optl, mn.second);
solve(md+1, r, layer, mn.second, optr);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>d>>T;
for (int i=1; i<=n; i++) cin>>t[i];
for (int i=0; i<=n; i++) for (int j=0; j<=n; j++) dp[i][j]=1e9;
dp[0][0]=0;
for (int i=1; i<=n; i++)
{
int cnt=0, lst=1e9;
for (int j=i; j<=n; j++) lst=min(lst+1, t[j]), cnt+=(lst<=T), c[i][j]=cnt;
}
for (int i=1; i<=d+1; i++) solve(i, n, i, i, n);
//for (int i=1; i<=d+1; i++) for (int j=1; j<=n; j++) cout<<i<<' '<<j<<' '<<dp[i][j]<<'\n';
cout<<dp[d+1][n];
}
# | 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... |