답안 #441153

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441153 2021-07-04T12:29:24 Z Vladth11 K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1 ms 332 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 100001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 1000000007;
const ll BLOCK = 318;
const ll base = 31;
const ll nr_of_bits = 21;
const ll LIMIT = 1000;

ll dp[NMAX][101]; ///aici mai putem scoate chestii
ll n, k;
priority_queue <pii> pq[101];
ll v[NMAX];
ll stiva[NMAX];
ll vf;
ll f[NMAX];

int main() {
    ll i;
    cin >> n >> k;
    for(i = 1; i <= n; i++){
        cin >> v[i];
    }
    for(i = 0; i <= n; i++){
        for(ll j = 0; j <= k; j++)
            dp[i][j] = HALF;
    }
    dp[0][0] = 0;
    for(i = 1; i <= n; i++){
        while(vf && v[stiva[vf]] <= v[i]){
            f[stiva[vf]]--;
            vf--;
        }
        stiva[++vf] = i;
        f[i]++;
        for(ll j = 1; j <= min(i, k); j++){
            ll val = dp[stiva[vf - 1]][j - 1] + v[i];
            if(stiva[vf - 1] <= j - 1){
                val = dp[j - 1][j - 1] + v[i];
            }
            pq[j].push({-val, i});
        }
        for(ll j = 1; j <= min(i, k); j++){
            while(pq[j].size() && !f[pq[j].top().second])
                pq[j].pop();
            ll cost = -pq[j].top().first;
            dp[i][j] = min(dp[i][j], cost);
        }
    }
    cout << dp[n][k];
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Incorrect 0 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -