답안 #230130

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
230130 2020-05-08T16:46:16 Z DodgeBallMan K개의 묶음 (IZhO14_blocks) C++14
100 / 100
333 ms 85232 KB
#include <bits/stdc++.h>
 
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define all(s) s.begin(), s.end()
 
using namespace std;
 
const int N = 1e5 + 5;
 
int n, k, a[N];
 
long long dp[N][105];
 
vector <pair< pair<int, long long>, long long> > vec;
 
int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}
	memset(dp, 0x3f3f3f3f, sizeof(dp));
	dp[0][0] = 0;
	for (int j = 1; j <= k; j++) {
		vec.clear();
		for (int i = 1; i <= n; i++) {
			long long mn = dp[i - 1][j - 1];
			while (!vec.empty() && vec.back().fr.fr <= a[i]) {
				mn = min(mn, vec.back().fr.sc);
				vec.pop_back();
			}
			long long val = a[i] + mn;
			if (!vec.empty()) 
				val = min(val, vec.back().sc);
				
			vec.pb({{a[i], mn}, val});
			dp[i][j] = val;
		}
	}	
	cout << dp[n][k]<< endl;
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 82556 KB Output is correct
2 Correct 45 ms 82552 KB Output is correct
3 Correct 47 ms 82552 KB Output is correct
4 Correct 44 ms 82552 KB Output is correct
5 Correct 47 ms 82552 KB Output is correct
6 Correct 46 ms 82552 KB Output is correct
7 Correct 45 ms 82552 KB Output is correct
8 Correct 44 ms 82552 KB Output is correct
9 Correct 44 ms 82552 KB Output is correct
10 Correct 47 ms 82552 KB Output is correct
11 Correct 46 ms 82552 KB Output is correct
12 Correct 45 ms 82552 KB Output is correct
13 Correct 45 ms 82552 KB Output is correct
14 Correct 46 ms 82552 KB Output is correct
15 Correct 47 ms 82552 KB Output is correct
16 Correct 45 ms 82552 KB Output is correct
17 Correct 46 ms 82552 KB Output is correct
18 Correct 46 ms 82560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 82552 KB Output is correct
2 Correct 45 ms 82552 KB Output is correct
3 Correct 45 ms 82552 KB Output is correct
4 Correct 45 ms 82552 KB Output is correct
5 Correct 47 ms 82560 KB Output is correct
6 Correct 44 ms 82552 KB Output is correct
7 Correct 46 ms 82552 KB Output is correct
8 Correct 45 ms 82552 KB Output is correct
9 Correct 45 ms 82552 KB Output is correct
10 Correct 45 ms 82552 KB Output is correct
11 Correct 44 ms 82552 KB Output is correct
12 Correct 44 ms 82552 KB Output is correct
13 Correct 45 ms 82552 KB Output is correct
14 Correct 45 ms 82556 KB Output is correct
15 Correct 46 ms 82552 KB Output is correct
16 Correct 44 ms 82556 KB Output is correct
17 Correct 47 ms 82552 KB Output is correct
18 Correct 50 ms 82552 KB Output is correct
19 Correct 46 ms 82552 KB Output is correct
20 Correct 45 ms 82560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 82560 KB Output is correct
2 Correct 45 ms 82552 KB Output is correct
3 Correct 44 ms 82552 KB Output is correct
4 Correct 45 ms 82552 KB Output is correct
5 Correct 45 ms 82560 KB Output is correct
6 Correct 44 ms 82552 KB Output is correct
7 Correct 45 ms 82552 KB Output is correct
8 Correct 45 ms 82552 KB Output is correct
9 Correct 46 ms 82552 KB Output is correct
10 Correct 44 ms 82552 KB Output is correct
11 Correct 46 ms 82552 KB Output is correct
12 Correct 45 ms 82552 KB Output is correct
13 Correct 45 ms 82552 KB Output is correct
14 Correct 46 ms 82484 KB Output is correct
15 Correct 46 ms 82552 KB Output is correct
16 Correct 46 ms 82552 KB Output is correct
17 Correct 46 ms 82552 KB Output is correct
18 Correct 45 ms 82560 KB Output is correct
19 Correct 46 ms 82572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 82552 KB Output is correct
2 Correct 52 ms 82940 KB Output is correct
3 Correct 56 ms 82944 KB Output is correct
4 Correct 126 ms 83192 KB Output is correct
5 Correct 295 ms 83576 KB Output is correct
6 Correct 65 ms 83576 KB Output is correct
7 Correct 166 ms 83576 KB Output is correct
8 Correct 45 ms 82552 KB Output is correct
9 Correct 45 ms 82556 KB Output is correct
10 Correct 47 ms 82552 KB Output is correct
11 Correct 46 ms 82552 KB Output is correct
12 Correct 46 ms 82552 KB Output is correct
13 Correct 47 ms 82552 KB Output is correct
14 Correct 66 ms 82552 KB Output is correct
15 Correct 47 ms 82552 KB Output is correct
16 Correct 53 ms 82552 KB Output is correct
17 Correct 54 ms 82936 KB Output is correct
18 Correct 59 ms 83064 KB Output is correct
19 Correct 128 ms 83064 KB Output is correct
20 Correct 333 ms 83704 KB Output is correct
21 Correct 68 ms 83576 KB Output is correct
22 Correct 191 ms 83576 KB Output is correct
23 Correct 61 ms 83576 KB Output is correct
24 Correct 86 ms 83576 KB Output is correct
25 Correct 326 ms 83704 KB Output is correct
26 Correct 46 ms 82552 KB Output is correct
27 Correct 44 ms 82552 KB Output is correct
28 Correct 67 ms 82812 KB Output is correct
29 Correct 47 ms 82808 KB Output is correct
30 Correct 51 ms 82808 KB Output is correct
31 Correct 52 ms 83564 KB Output is correct
32 Correct 58 ms 83512 KB Output is correct
33 Correct 124 ms 83560 KB Output is correct
34 Correct 322 ms 85232 KB Output is correct
35 Correct 68 ms 85232 KB Output is correct
36 Correct 180 ms 85232 KB Output is correct
37 Correct 49 ms 82680 KB Output is correct
38 Correct 64 ms 82676 KB Output is correct
39 Correct 45 ms 82552 KB Output is correct
40 Correct 45 ms 82556 KB Output is correct
41 Correct 45 ms 82552 KB Output is correct
42 Correct 45 ms 82552 KB Output is correct