답안 #1092518

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1092518 2024-09-24T10:00:41 Z K30_Thua_Phong K개의 묶음 (IZhO14_blocks) C++17
0 / 100
2 ms 348 KB
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
using namespace std;
const int N = 100005;
ll n, k, amax = 0;
ll a[N + 2], dp[N + 2][150];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    freopen("blocks.in", "r", stdin);
    freopen("blocks.out", "w", stdout);
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        dp[i][1] = max(dp[i - 1][1], a[i]);
    }
    for(int i = 1; i <= n; i++)
    {
        for(int d = 2; d <= k; d++)
            dp[i][d] = INT_MAX;
    }
    for(int d = 2; d <= k; d++)
    {
        for(int i = d; i <= n; i++)
        {
            amax = a[i];
            for(int j = i - 1; j >= d - 1; j--) {
                dp[i][d] = min(dp[i][d], dp[j][d - 1] + amax);
                amax = max(amax, a[j]);
            }
        }
    }
    cout << dp[n][k];
    return 0;
}
/*
5 2
1 2 3 4 5
*/

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("blocks.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     freopen("blocks.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -