답안 #443095

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
443095 2021-07-09T16:09:59 Z BeanZ K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 332 KB
// I_Love_LPL 1y0m1d
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
long long mod = 1000007;
const int lim = 4e5 + 5;
const int lg = 20;
const int base = 311;
const long double eps = 1e-6;
ll dp[N][105], a[N];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("tests.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for (int i = 1; i <= n; i++){
        dp[i][1] = a[i];
    }
    for (int j = 2; j <= k; j++){
        vector<pair<ll, ll>> mem;
        for (int i = j; i <= n; i++){
            ll v = dp[i - 1][j - 1];
            while (mem.size() && a[i] >= mem.back().first){
                if (v > mem.back().second) v = mem.back().second;
                mem.pop_back();
            }
            if (!mem.size() || (v + a[i]) < (mem.back().first + mem.back().second)) mem.push_back({a[i], v});
            dp[i][j] = mem.back().first + mem.back().second;
        }
    }
    cout << dp[n][k];
}
/*
Ans:

Out:
*/

Compilation message

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