답안 #1077131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1077131 2024-08-27T01:29:02 Z duyhoanho K개의 묶음 (IZhO14_blocks) C++14
0 / 100
29 ms 80284 KB
#include <bits/stdc++.h>
#define task ""
#define int long long
#define forinc(i,a,b) for(int i=a;i<=b;i++)
using namespace std;
const int N=1e5+10;
int n,a[N],dp[N][102],k;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    if (fopen ("blocks.in", "r"))
    {
        freopen ("blocks.in", "r", stdin);
        freopen ("blocks.out", "w", stdout);
    }
    cin>>n>>k;
    memset(dp,99,sizeof dp);
    int mx=0;
    forinc(i,1,n)
    {
        cin>>a[i];
        mx=max(mx,a[i]);
        dp[i][1] = mx;

    }

    for(int j=2; j<=k; j++)
    {
        stack<int> st;
        for(int i=1; i<=n; i++)
        {
            while(st.size() && a[st.top()] <= a[i] )
            {

                dp[i][j] = min(dp[i][j], dp[st.top()][j-1] + a[i]);
                dp[i][j] = min(dp[i][j],dp[st.top()][j] - a[st.top()] + a[i]);
                st.pop();
            }
            if(st.size())
            {
                dp[i][j] = min(dp[i][j], dp[st.top()][j-1] + a[i]);
                dp[i][j] = min(dp[i][j],dp[st.top()][j] - a[st.top()] + a[i]);
            }
            st.push(i);
        }
    }
    cout<<dp[n][k];
}

Compilation message

blocks.cpp: In function 'int32_t main()':
blocks.cpp:15:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |         freopen ("blocks.in", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:16:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen ("blocks.out", "w", stdout);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 80212 KB Output is correct
2 Correct 23 ms 80220 KB Output is correct
3 Correct 26 ms 80120 KB Output is correct
4 Correct 24 ms 80220 KB Output is correct
5 Correct 22 ms 80212 KB Output is correct
6 Correct 23 ms 80216 KB Output is correct
7 Correct 22 ms 80208 KB Output is correct
8 Correct 20 ms 80216 KB Output is correct
9 Correct 22 ms 80248 KB Output is correct
10 Incorrect 22 ms 80220 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 80216 KB Output is correct
2 Correct 23 ms 80276 KB Output is correct
3 Correct 22 ms 80208 KB Output is correct
4 Correct 23 ms 80284 KB Output is correct
5 Correct 22 ms 80216 KB Output is correct
6 Correct 24 ms 80208 KB Output is correct
7 Correct 21 ms 80124 KB Output is correct
8 Correct 22 ms 80200 KB Output is correct
9 Correct 22 ms 80284 KB Output is correct
10 Incorrect 22 ms 80208 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 80212 KB Output is correct
2 Correct 23 ms 80220 KB Output is correct
3 Correct 26 ms 80120 KB Output is correct
4 Correct 24 ms 80220 KB Output is correct
5 Correct 22 ms 80212 KB Output is correct
6 Correct 23 ms 80216 KB Output is correct
7 Correct 22 ms 80208 KB Output is correct
8 Correct 20 ms 80216 KB Output is correct
9 Correct 22 ms 80248 KB Output is correct
10 Incorrect 22 ms 80220 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 80212 KB Output is correct
2 Correct 23 ms 80220 KB Output is correct
3 Correct 26 ms 80120 KB Output is correct
4 Correct 24 ms 80220 KB Output is correct
5 Correct 22 ms 80212 KB Output is correct
6 Correct 23 ms 80216 KB Output is correct
7 Correct 22 ms 80208 KB Output is correct
8 Correct 20 ms 80216 KB Output is correct
9 Correct 22 ms 80248 KB Output is correct
10 Incorrect 22 ms 80220 KB Output isn't correct
11 Halted 0 ms 0 KB -