답안 #602383

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602383 2022-07-23T02:41:16 Z Doanxem99 K개의 묶음 (IZhO14_blocks) C++14
0 / 100
38 ms 87208 KB
//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++)
   	{
   		int minF;
   		stack< ar > s;
   		for (int j = 1; j <= n; j++)
   		{
   			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] ;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 87116 KB Output is correct
2 Correct 38 ms 87172 KB Output is correct
3 Correct 36 ms 87148 KB Output is correct
4 Incorrect 38 ms 87188 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 87184 KB Output is correct
2 Correct 36 ms 87116 KB Output is correct
3 Correct 37 ms 87140 KB Output is correct
4 Incorrect 37 ms 87208 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 87116 KB Output is correct
2 Correct 38 ms 87172 KB Output is correct
3 Correct 36 ms 87148 KB Output is correct
4 Incorrect 38 ms 87188 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 87116 KB Output is correct
2 Correct 38 ms 87172 KB Output is correct
3 Correct 36 ms 87148 KB Output is correct
4 Incorrect 38 ms 87188 KB Output isn't correct
5 Halted 0 ms 0 KB -