답안 #242047

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
242047 2020-06-26T16:02:20 Z przxct K개의 묶음 (IZhO14_blocks) C++17
0 / 100
7 ms 640 KB
#include <bits/stdc++.h>
#define fto(i,j,h)      for (int i=j; i<=h; ++i)
#define fdto(i,j,h)     for (int i=j; i>=h; --i)
#define przxct "main"
#define maxn 100003
#define fi first
#define se second
#define ll long long
#define db double
#define pi 3.141592653589

using namespace std;

int n, k, a[maxn];
ll F[103][maxn];
stack<int> t;
stack<pair<int, ll> > t2;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen(przxct".inp", "r", stdin);
    freopen(przxct".out", "w", stdout);
    #endif // ONLINE_JUDGE
    cin >> n >> k;
    fto(i,1,n)      cin >> a[i];
    int Max = 0;
    fto(i,1,n){
       Max = max(Max, a[i]);
       F[1][i] = Max;
    }
    fto(i,2,k)
      fto(j,1,n){
         F[i][j] = 1e18;
      }
    fto(g,2,k){
      t2.push({g-1, F[g-1][g-1]});
      fto(i,g,n){
         while (t.empty() == false && a[t.top()] <= a[i]){
             t.pop();
         }
         if (t.empty() == false)   F[g][i] = max(F[g][i], F[g][t.top()]);
         t.push(i);
         ll Min = 1e18;
         while (t2.empty() == false && a[t2.top().fi] <= a[i]){
            Min = min(Min, min(t2.top().se, F[g-1][t2.top().fi]));
            t2.pop();
         }
         if (t2.empty() == false)    Min = min(Min, F[g-1][t2.top().fi]);
         F[g][i] = min(F[g][i], Min + a[i]);
         t2.push({i, Min});
      }
    }
    cout << F[k][n];
    return 0;
}

Compilation message

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