Submission #922530

#TimeUsernameProblemLanguageResultExecution timeMemory
922530phongK blocks (IZhO14_blocks)C++17
53 / 100
1010 ms166724 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma") #pragma GCC optimize("unroll-loops") #include<bits/stdc++.h> #define ll long long const int nmax = 1e5 + 5; const ll oo = 1e18, base = 311; const int lg = 19, M = 105; const ll mod = 1e9 + 7; #define pii pair<ll, int> #define fi first #define se second #define debug(a, n) for(int i = 1; i <= n; ++i) cout << a[i] << ' '; using namespace std; int n, k; ll f[nmax][M], a[nmax], mi[nmax][M]; void ckmax(ll &a, ll b){ a = max(a, b); } void ckmin(ll &a, ll b){ a = min(a, b); } deque<int> de; multiset<pii> mt; int L[nmax]; main(){ ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // freopen("code.inp", "r", stdin); // freopen("code.out", "w", stdout); cin >> n >> k; memset(f, 0x3f, sizeof f); memset(mi, 0x3f, sizeof f); for(int i = 1; i <= n; ++i){ cin >> a[i]; if(i == 1) f[1][1] = a[i]; else f[i][1] = max(f[i - 1][1], a[i]); } for(int j = 1; j <= k; ++j){ de.clear();mt.clear(); for(int i = 1; i <= n; ++i){ if(j > 1){ while(de.size() && a[de.back()] <= a[i]){ int u = de.back(); mt.erase({mi[u][j - 1] + a[u], u}); de.pop_back(); } de.push_back(i); mt.insert({mi[i][j - 1] + a[i], i}); auto it = *mt.begin(); f[i][j] = it.fi; } L[i] = i - 1; mi[i][j] = f[i - 1][j]; while(L[i] && a[L[i]] <= a[i]){ ckmin(mi[i][j],mi[L[i]][j]); L[i] = L[L[i]]; } } } cout << f[n][k]; } /* 5 2 1 2 3 4 5 */

Compilation message (stderr)

blocks.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...