답안 #684833

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
684833 2023-01-22T15:04:02 Z vjudge1 K개의 묶음 (IZhO14_blocks) C++14
0 / 100
35 ms 80140 KB
#include <bits/stdc++.h>
using namespace std; 

const int mod = 1e9 + 7; 
const auto seed = chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 ran(seed);

#define ll long long
#define int long long
#define se second
#define fi first
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define REP(i, a, b) for (int i = (a), _b = (b); i < _b; i++)
#define FOD(i,r,l) for(int i=r; i>=l; i--)


int n, k; 
int a[200000];
int f[100004][102];

signed main(){
#define task "a"
    if(fopen(task".inp","r")) {
        freopen(task".inp","r",stdin);
        freopen(task".out","w",stdout);
    }

    cin >> n >> k; 

    memset(f, 0x3f, sizeof f);
    f[0][1] = 0 ; 
    FOR(i ,1, n) cin >> a[i], f[i][1] = max(f[i-1][1], a[i]);

    FOR(j ,2, k){
        stack <pair <int,int>> st; 
        FOR(i ,1, n){
            int mn = 1e9; 
            while(st.size() && a[st.top().fi] < a[i]){
                mn = min(mn, st.top().se);
                st.pop();
            }
            f[i][j] = min(f[i][j], mn + a[i]);
            if(st.size()) f[i][j] = min(f[i][j], st.top().se + a[st.top().fi + 1]);

            st.push(make_pair(i, f[i][j-1]));
        }
    }

    cout << f[n][k]; 
}










Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   24 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:25:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         freopen(task".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 80044 KB Output is correct
2 Correct 30 ms 80084 KB Output is correct
3 Correct 32 ms 80076 KB Output is correct
4 Correct 30 ms 80108 KB Output is correct
5 Correct 32 ms 80140 KB Output is correct
6 Correct 35 ms 80104 KB Output is correct
7 Incorrect 31 ms 80060 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 29 ms 80052 KB Output is correct
2 Correct 29 ms 80084 KB Output is correct
3 Correct 29 ms 80072 KB Output is correct
4 Correct 31 ms 80088 KB Output is correct
5 Correct 29 ms 80128 KB Output is correct
6 Correct 30 ms 80084 KB Output is correct
7 Incorrect 30 ms 80124 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 80044 KB Output is correct
2 Correct 30 ms 80084 KB Output is correct
3 Correct 32 ms 80076 KB Output is correct
4 Correct 30 ms 80108 KB Output is correct
5 Correct 32 ms 80140 KB Output is correct
6 Correct 35 ms 80104 KB Output is correct
7 Incorrect 31 ms 80060 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 80044 KB Output is correct
2 Correct 30 ms 80084 KB Output is correct
3 Correct 32 ms 80076 KB Output is correct
4 Correct 30 ms 80108 KB Output is correct
5 Correct 32 ms 80140 KB Output is correct
6 Correct 35 ms 80104 KB Output is correct
7 Incorrect 31 ms 80060 KB Output isn't correct
8 Halted 0 ms 0 KB -