이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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];
pii stiva[NMAX][101];
ll vf[101];
ll f[NMAX];
ll best[NMAX][101];
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 = 0; i <= k; i++)
best[0][i] = HALF;
for(i = 1; i <= n; i++){
for(ll j = 1; j <= min(i, k); j++){
ll minim = dp[i - 1][j - 1];
while(vf[j] && v[stiva[vf[j]][j].second] <= v[i]){
minim = min(minim, stiva[vf[j]][j].first);
vf[j]--;
}
dp[i][j] = min({dp[i][j], minim + v[i], best[vf[j]][j]});
stiva[++vf[j]][j] = {minim, i};
best[vf[j]][j] = min(best[vf[j] - 1][j], minim + v[i]);
}
}
cout << dp[n][k];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |