# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
716154 | ktkerem | K blocks (IZhO14_blocks) | C++17 | 1 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")/**/
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
typedef __int128 vll;
typedef long long ftyp;
typedef std::complex<ftyp> vec;
#define llll std::pair<ll , ll>
#define pb push_back
#define fi first
#define sec second
#define cx real
#define cy imag
#define all(a) a.begin() , a.end()
#define debug std::cout << "!!ALERT ALERT!!" << std::endl;
const ll limit = 1e15+7;
const ll sus = 1e5+5;
std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
ll n , m;std::vector<ll> ar;
ll dp[105][sus];
void solve(){
std::cin >> n >> m;
ar.resize(n+5);
dp[1][0] = limit;
for(ll i = 1;n>=i;i++){
std::cin >> ar[i];
}
dp[1][1] = ar[1];
for(ll i = 2;n>=i;i++){
dp[1][i] = std::max(dp[1][i-1] , ar[i]);
}
for(ll k = 2;m>=k;k++){
std::stack<ll> s1 , s2;
for(ll j = 1;n>=j;j++){
ll ff = dp[k-1][j-1];
while(!s1.empty() && s1.top() < ar[j]){
ff = std::min(ff , s2.top());
s1.pop();
s2.pop();
}
if(s1.empty() || ff + ar[j] < s1.top() + s2.top()){
s1.push(ar[j]);
s2.push(ff);
}
if(j >= k){
dp[k][j] = s1.top() + s2.top();
}
}
}
std::cout << dp[m][n];
return;/**/
}
int main(){
std::ios_base::sync_with_stdio(false);std::cin.tie(NULL);
ll t = 1;
//std::cin >> t;
while(t--){
solve();
}
}
Compilation message (stderr)
# | 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... |