답안 #1035957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035957 2024-07-26T20:24:57 Z pera K개의 묶음 (IZhO14_blocks) C++17
53 / 100
1000 ms 6984 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n , k , a[N] , l[N] , dp[N];
struct node{
   int dp_min , mn , lz;
};
vector<node> t(4 * N);
node merge(node x , node y){
   x.dp_min = min(x.dp_min , y.dp_min);
   x.mn = min(x.mn , y.mn);
   return x;
}
void push(int u){
   if(t[u].lz == -1){
      return;
   }
   t[u * 2].mn = t[u].lz + t[u * 2].dp_min;
   t[u * 2 + 1].mn = t[u].lz + t[u * 2 + 1].mn;
   t[u * 2].lz = t[u].lz;
   t[u * 2 + 1].lz = t[u].lz;
   t[u].lz = -1;
}
void build(int u , int l , int r){
   if(l == r){
      t[u].dp_min = dp[l - 1];
      t[u].mn = 1e9;
      t[u].lz = -1;
      return;
   }
   int m = (l + r) / 2;
   build(u * 2 , l , m);
   build(u * 2 + 1 , m + 1 , r);
   t[u] = merge(t[u * 2] , t[u * 2 + 1]);
}
void upd(int u , int l , int r , int L , int R , int x){
   if(l > r || r < L || l > R){
      return;
   }
   if(L <= l && r <= R){
      t[u].mn = t[u].dp_min + x;
      t[u].lz = x;
      return;
   }
   int m = (l + r) / 2;
   upd(u * 2 , l , m , L , R , x);
   upd(u * 2 + 1 , m + 1 , r , L , R , x);
   t[u] = merge(t[u * 2] , t[u * 2 + 1]);
}
int main(){
   ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin >> n >> k;
   int _mx = 0;
   dp[0] = 1e9;
   for(int i = 1;i <= n;i ++){
      cin >> a[i];
      l[i] = i - 1;
      while(l[i] > 0 && a[i] > a[l[i]]){
         l[i] = l[l[i]];
      }
      _mx = max(_mx , a[i]);
      dp[i] =_mx;
   }
   for(int x = 1;x < k;x ++){
      build(1 , 1 , n);
      for(int i = 1;i <= n;i ++){
         upd(1 , 1 , n , l[i] + 1 , i , a[i]);
         dp[i] = t[1].mn;
      }
   }
   cout << dp[n] << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5180 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4968 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 5152 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 5180 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 3 ms 4952 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4984 KB Output is correct
17 Correct 3 ms 4956 KB Output is correct
18 Correct 2 ms 4984 KB Output is correct
19 Correct 3 ms 5184 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5180 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4968 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 3 ms 5152 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 5180 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 3 ms 4952 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4984 KB Output is correct
35 Correct 3 ms 4956 KB Output is correct
36 Correct 2 ms 4984 KB Output is correct
37 Correct 3 ms 5184 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 5340 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4952 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 5184 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 3 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4952 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 3 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 3 ms 4952 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 2 ms 5180 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 2 ms 4956 KB Output is correct
8 Correct 2 ms 4956 KB Output is correct
9 Correct 2 ms 4956 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 2 ms 4952 KB Output is correct
13 Correct 2 ms 5208 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 2 ms 4956 KB Output is correct
16 Correct 2 ms 4956 KB Output is correct
17 Correct 2 ms 4952 KB Output is correct
18 Correct 2 ms 4952 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4968 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 3 ms 5152 KB Output is correct
24 Correct 2 ms 4956 KB Output is correct
25 Correct 2 ms 4956 KB Output is correct
26 Correct 2 ms 4956 KB Output is correct
27 Correct 2 ms 4956 KB Output is correct
28 Correct 2 ms 4956 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 5180 KB Output is correct
31 Correct 2 ms 4956 KB Output is correct
32 Correct 3 ms 4952 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 2 ms 4984 KB Output is correct
35 Correct 3 ms 4956 KB Output is correct
36 Correct 2 ms 4984 KB Output is correct
37 Correct 3 ms 5184 KB Output is correct
38 Correct 2 ms 4956 KB Output is correct
39 Correct 2 ms 4956 KB Output is correct
40 Correct 2 ms 4956 KB Output is correct
41 Correct 2 ms 4956 KB Output is correct
42 Correct 2 ms 4956 KB Output is correct
43 Correct 2 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 5340 KB Output is correct
46 Correct 2 ms 5212 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 2 ms 4952 KB Output is correct
50 Correct 2 ms 4956 KB Output is correct
51 Correct 2 ms 5184 KB Output is correct
52 Correct 2 ms 4956 KB Output is correct
53 Correct 3 ms 4956 KB Output is correct
54 Correct 2 ms 4956 KB Output is correct
55 Correct 2 ms 4952 KB Output is correct
56 Correct 2 ms 4956 KB Output is correct
57 Correct 3 ms 4956 KB Output is correct
58 Correct 29 ms 5208 KB Output is correct
59 Correct 5 ms 5980 KB Output is correct
60 Correct 42 ms 5988 KB Output is correct
61 Correct 397 ms 5980 KB Output is correct
62 Execution timed out 1034 ms 6984 KB Time limit exceeded
63 Halted 0 ms 0 KB -