# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
140655 | 2019-08-04T09:29:28 Z | rzbt | K개의 묶음 (IZhO14_blocks) | C++14 | 178 ms | 4176 KB |
#include <bits/stdc++.h> #define mp make_pair #define pb push_back #define F first #define S second #define all(x) x.begin(),x.end() #define MAXN 100005 typedef long long ll; using namespace std; ll n,k; ll niz[MAXN]; ll dpp[MAXN],dp[MAXN]; stack<pair<ll,ll> > s; int main() { scanf("%lld %lld", &n, &k); for(ll i=1;i<=n;i++) scanf("%lld",niz+i); dp[0]=dpp[0]=1e9; ll tmax=0; for(ll i=1;i<=n;i++){ tmax=max(tmax,niz[i]); dpp[i]=tmax; } for(ll j=1;j<k;j++){ //for(ll i=1;i<=n;i++)printf(" %d\n",dpp[i]); //printf("\n\n\n"); for(ll i=1;i<=n;i++){ ll tS = dpp[i-1]; while(!s.empty() && niz[s.top().F] < niz[i]){ tS=min(tS,s.top().S); s.pop(); } if(!s.empty())dp[i]=min(dp[s.top().F],niz[i]+tS); else dp[i]=niz[i]+tS; s.push(mp(i,tS)); } for(ll i=1;i<=n;i++)dpp[i]=dp[i]; while(!s.empty())s.pop(); } printf("%lld",dpp[n]); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 348 KB | Output is correct |
18 | Correct | 2 ms | 380 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 504 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 372 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 364 KB | Output is correct |
6 | Correct | 2 ms | 348 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 376 KB | Output is correct |
14 | Correct | 2 ms | 376 KB | Output is correct |
15 | Correct | 2 ms | 376 KB | Output is correct |
16 | Correct | 2 ms | 376 KB | Output is correct |
17 | Correct | 2 ms | 376 KB | Output is correct |
18 | Correct | 2 ms | 376 KB | Output is correct |
19 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 632 KB | Output is correct |
2 | Correct | 8 ms | 1400 KB | Output is correct |
3 | Correct | 12 ms | 1656 KB | Output is correct |
4 | Correct | 46 ms | 1656 KB | Output is correct |
5 | Correct | 127 ms | 3320 KB | Output is correct |
6 | Correct | 21 ms | 3320 KB | Output is correct |
7 | Correct | 69 ms | 3320 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
12 | Correct | 2 ms | 376 KB | Output is correct |
13 | Correct | 2 ms | 380 KB | Output is correct |
14 | Correct | 18 ms | 632 KB | Output is correct |
15 | Correct | 4 ms | 632 KB | Output is correct |
16 | Correct | 7 ms | 632 KB | Output is correct |
17 | Correct | 9 ms | 1400 KB | Output is correct |
18 | Correct | 14 ms | 1656 KB | Output is correct |
19 | Correct | 59 ms | 1656 KB | Output is correct |
20 | Correct | 170 ms | 3384 KB | Output is correct |
21 | Correct | 22 ms | 3320 KB | Output is correct |
22 | Correct | 85 ms | 3320 KB | Output is correct |
23 | Correct | 18 ms | 2556 KB | Output is correct |
24 | Correct | 31 ms | 3320 KB | Output is correct |
25 | Correct | 169 ms | 3320 KB | Output is correct |
26 | Correct | 2 ms | 376 KB | Output is correct |
27 | Correct | 2 ms | 376 KB | Output is correct |
28 | Correct | 18 ms | 632 KB | Output is correct |
29 | Correct | 4 ms | 760 KB | Output is correct |
30 | Correct | 7 ms | 760 KB | Output is correct |
31 | Correct | 8 ms | 1400 KB | Output is correct |
32 | Correct | 12 ms | 2040 KB | Output is correct |
33 | Correct | 58 ms | 2040 KB | Output is correct |
34 | Correct | 178 ms | 4176 KB | Output is correct |
35 | Correct | 20 ms | 4088 KB | Output is correct |
36 | Correct | 87 ms | 4088 KB | Output is correct |
37 | Correct | 4 ms | 632 KB | Output is correct |
38 | Correct | 14 ms | 632 KB | Output is correct |
39 | Correct | 2 ms | 380 KB | Output is correct |
40 | Correct | 3 ms | 376 KB | Output is correct |
41 | Correct | 2 ms | 380 KB | Output is correct |
42 | Correct | 2 ms | 376 KB | Output is correct |