Submission #602385

#TimeUsernameProblemLanguageResultExecution timeMemory
602385Doanxem99K blocks (IZhO14_blocks)C++14
53 / 100
41 ms87268 KiB
//Link : //Author: Nguyen Dinh Manh #include <bits/stdc++.h> using namespace std; #define timing "Time collapse : " << fixed << setprecision(3) << 1.000 * clock() / CLOCKS_PER_SEC #define int long long #define ar array< int , 2> #define MASK(i) (1 << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define task "" template<typename T1, typename T2> bool minN(T1 &a, T2 b) {if (a > b) a = b; else return 0; return 1;} template<typename T1, typename T2> bool maxX(T1 &a, T2 b) {if (a < b) a = b; else return 0; return 1;} const int MAX = 100011, INFL = 1e9 + 7, INFLL = 1e18 + 7; int n, f[MAX][111], a[MAX], k; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //freopen(task".inp","r", stdin); freopen(task".out","w",stdout); cin >> n >> k; for (int i = 1; i <= n; i++) { cin >> a[i]; } memset(f, 0x3f, sizeof f); f[1][0] = 0; for (int i = 1; i <= n; i++) minN(f[1][i], max(f[1][i - 1], a[i])); for (int i = 2; i <= k; ++i) { stack< ar > s; for (int j = i; j <= n; ++j) { int minF = f[i - 1][j - 1]; while (!s.empty() && a[s.top()[1]] <= a[j]) { minN(minF, s.top()[0]); s.pop(); } f[i][j] = min(f[i][(s.empty() ? 0 : s.top()[1])], minF + a[j]); s.push({minF, j}); } //for (int j = 1; j <= n; j++) cout << f[i][j] << " \n"[j == n]; } cout << f[k][n] ; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...