제출 #441199

#제출 시각아이디문제언어결과실행 시간메모리
441199Vladth11K개의 묶음 (IZhO14_blocks)C++14
0 / 100
1 ms332 KiB
#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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...