답안 #930607

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
930607 2024-02-20T07:50:53 Z ArgoCahaya Stove (JOI18_stove) C++14
50 / 100
1000 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e3;
const int INF = 2e9;
int n, k;
int a[MAXN + 5];
int dp[MAXN + 1][MAXN + 1][2];

int f(int idx, int cnt, int state)
{
    if (cnt > k)
        return INF;
    if (idx == n)
    {
        if (state == 1)
            return 0;
        else
        {
            if (cnt < k)
                return 1;
            return INF;
        }
    }

    int &ret = dp[idx][cnt][state];
    if (ret != -1)
        return ret;

    ret = INF;
    if (state)
    {
        ret = min(ret, f(idx + 1, cnt, 1) + (a[idx + 1] - a[idx]));
        ret = min(ret, f(idx + 1, cnt, 0) + (a[idx + 1] - a[idx]));
    }
    else
    {
        ret = min(ret, f(idx + 1, cnt + 1, 1) + 1);
        ret = min(ret, f(idx + 1, cnt + 1, 0) + 1);
    }
    return ret;
}

int main()
{
    memset(dp, -1, sizeof(dp));
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    cout << f(0, 0, 0) << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 196200 KB Output is correct
2 Correct 39 ms 196184 KB Output is correct
3 Correct 39 ms 196248 KB Output is correct
4 Correct 39 ms 196180 KB Output is correct
5 Correct 39 ms 196004 KB Output is correct
6 Correct 37 ms 196180 KB Output is correct
7 Correct 39 ms 196180 KB Output is correct
8 Correct 39 ms 196176 KB Output is correct
9 Correct 40 ms 195964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 196200 KB Output is correct
2 Correct 39 ms 196184 KB Output is correct
3 Correct 39 ms 196248 KB Output is correct
4 Correct 39 ms 196180 KB Output is correct
5 Correct 39 ms 196004 KB Output is correct
6 Correct 37 ms 196180 KB Output is correct
7 Correct 39 ms 196180 KB Output is correct
8 Correct 39 ms 196176 KB Output is correct
9 Correct 40 ms 195964 KB Output is correct
10 Correct 40 ms 196264 KB Output is correct
11 Correct 47 ms 196436 KB Output is correct
12 Correct 107 ms 196436 KB Output is correct
13 Correct 133 ms 196432 KB Output is correct
14 Correct 146 ms 196424 KB Output is correct
15 Correct 140 ms 196432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 196200 KB Output is correct
2 Correct 39 ms 196184 KB Output is correct
3 Correct 39 ms 196248 KB Output is correct
4 Correct 39 ms 196180 KB Output is correct
5 Correct 39 ms 196004 KB Output is correct
6 Correct 37 ms 196180 KB Output is correct
7 Correct 39 ms 196180 KB Output is correct
8 Correct 39 ms 196176 KB Output is correct
9 Correct 40 ms 195964 KB Output is correct
10 Correct 40 ms 196264 KB Output is correct
11 Correct 47 ms 196436 KB Output is correct
12 Correct 107 ms 196436 KB Output is correct
13 Correct 133 ms 196432 KB Output is correct
14 Correct 146 ms 196424 KB Output is correct
15 Correct 140 ms 196432 KB Output is correct
16 Execution timed out 1314 ms 262144 KB Time limit exceeded
17 Halted 0 ms 0 KB -