Submission #959317

# Submission time Handle Problem Language Result Execution time Memory
959317 2024-04-08T00:34:33 Z vjudge1 Stove (JOI18_stove) C++17
0 / 100
0 ms 344 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5003;
const int oo = 1e9 + 7;
int n, k; 

int times[MAXN];
int memo[MAXN][MAXN];

void opt()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
}

int dp (int i, int match)
{

    if (match == k)
    {
       // cout<<"call "<<i<<" "<<match<<" return oo"<<endl;
        return oo;
    }

    if (i == n -1)
    {
       // cout<<"call "<<i<<" "<<match<<" return 0"<<endl;
        return 0;
    }

   // cout<<"options for "<<i<<" "<<match<<endl;
    //cout<<i + 1<<", "<<match + 1<<" // "<<i + 1<<" , "<<match<<endl;

    

    if (memo[i + 1][match + 1] == -1)
    {
        memo[i + 1][match + 1] = dp(i + 1, match + 1);
    }

    if (memo[i + 1][match] == -1)
    {
        memo[i + 1][match] = dp(i + 1, match) + times[i + 1] - times[i] -1;
    }

    int a = memo[i + 1][match + 1];
    int b =  memo[i + 1][match];

    //cout<<"i "<<i<<" match "<<match<<endl;

    //cout<<"dif "<<a<<" same "<<b<<endl;

    return min(a, b) + 1;//por el tiempo de la persona
    
}

int main()
{
    opt();

    cin>>n>>k;

    for (int i = 0; i < n; i++)
    {
        cin>>times[i];
    }

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            memo[i][j] = -1;
        }
        
    }
    

    int resp = dp(0, 0);

    cout<<resp<<"\n";
    
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -