답안 #719765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719765 2023-04-06T15:47:18 Z josiftepe Stove (JOI18_stove) C++14
20 / 100
1000 ms 13580 KB
#include <bits/stdc++.h>
 
using namespace std;
 
int n,k;
int dp[5005][5005];
int x[5005];
 
int f(int idx,int p)
{
    if(idx==n+1)return 0;
    if(p==0)return 1e9;
    if(dp[idx][p]!=2e9)
    {
        return dp[idx][p];
    }
    int rez=1e9;
    for(int i=idx;i<=n;i++)
    {
        if(p-1>=0)
        {
            rez=min(rez, f(i+1,p-1)+x[i]-x[idx]+1);
        }
    }
    return dp[idx][p]=rez;
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=k;j++)
        {
            dp[i][j]=2e9;
        }
    }
    cout<<f(1,k)<<endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 331 ms 12552 KB Output is correct
11 Execution timed out 1090 ms 13580 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 331 ms 12552 KB Output is correct
11 Execution timed out 1090 ms 13580 KB Time limit exceeded
12 Halted 0 ms 0 KB -