Submission #345188

# Submission time Handle Problem Language Result Execution time Memory
345188 2021-01-07T06:21:26 Z l3nl3 K blocks (IZhO14_blocks) C++14
32 / 100
152 ms 512 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>  

#define exit exit(false)

//#define here() cerr << "herewego\n";
#define show(x) cerr << #x << ": " << x << '\n';

#define int long long
//#define double long double

#define all(a) a.begin(), a.end()
#define whole(a, p, q) a+p, a+p+q

#define ioio() ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);

using namespace std;

//using namespace __gnu_pbds;   
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  

const int mxsz = 1e5 + 7;

int n, k, a[mxsz], t[mxsz * 4], mn = LLONG_MAX, st[mxsz][21], lgg[mxsz+7];

int get (int l, int r) {
	int j = lgg[r-l+1];
	return max(st[l][j], st[r - (1 << j) + 1][j]);
}

signed main () { ioio();
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	lgg[1] = 0;
	for (int i = 2; i <= n; i++) {
		lgg[i] = lgg[i>>1] + 1;
	}
	for (int i = 0; i < n; i++)
	    st[i][0] = a[i];
	for (int j = 1; j <= 20; j++)
	    for (int i = 0; i + (1 << j) <= n; i++)
	        st[i][j] = max(st[i][j-1], st[i + (1 << (j - 1))][j - 1]);
	if (n <= 20) {
		for (int ma = 1; ma <= (1 << (n-1)); ma++) {
			vector <int> po;
			for (int i = 0; i < n-1; i++) {
				if ((1 << i) & ma) {
					po.push_back(i);
				}
			}
			if (po.size() == k-1) {
				po.push_back(n-1);
				int sm = 0;
				sm += get(0, po[0]);
				for (int i = 1; i < po.size(); i++) {
					sm += get(po[i-1] + 1, po[i]);
				}
				mn = min (mn, sm);
			}
		}
		cout << mn;
		exit;
	} else if (k <= 5) {
		n--;
		if (k == 1) {
			cout << get (0, n);
			exit;
		}
		if (k == 2) {
			for (int a = 1; a <= n; a++) {
				if (a == 1) {
					mn = get (0, a-1) + get (a, n);
					continue;
				}
				mn = min (mn, get (0, a-1) + get (a, n));
			}
			cout << mn;
			exit;
		}
		if (k == 3) {
			for (int a = 1; a <= n-1; a++) {
				for (int b = a+1; b <= n; b++) {
					if (a == 1 && b == 2) {
						mn = get (0, a-1) + get (a, b-1) + get (b, n);
						continue;
					}
					mn = min (mn, get (0, a-1) + get (a, b-1) + get (b, n));
				}
			}
			cout << mn;
			exit;
		}
		if (k == 4) {
			for (int a = 1; a <= n-2; a++) {
				for (int b = a+1; b <= n-1; b++) {
					for (int c = b+1; c <= n; c++) {
						if (a == 1 && b == 2 && c == 3) {
							mn = get (0, a-1) + get (a, b-1) + get (b, c-1) + get (c, n);
							continue;
						}
						mn = min (mn, get (0, a-1) + get (a, b-1) + get (b, c-1) + get (c, n));
					}
				}	
			}
			cout << mn;
			exit;
		}
		if (k == 5) {
			for (int a = 1; a <= n-3; a++) {
				for (int b = a+1; b <= n-2; b++) {
					for (int c = b+1; c <= n-1; c++) {
						for (int d = c+1; d <= n; d++) {
							if (a == 1 && b == 2 && c == 3 && d == 4) {
								mn = get (0, a-1) + get (a, b-1) + get (b, c-1) + get (c, d-1) + get (d, n);
								continue;
							}
							mn = min (mn, get (0, a-1) + get (a, b-1) + get (b, c-1) + get (c, d-1) + get (d, n));
						}
					}
				}
			}
			cout << mn;
			exit;
		}
	}
	else {
		cout << "wronganswer";
	}
}

Compilation message

blocks.cpp: In function 'int main()':
blocks.cpp:54:18: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   54 |    if (po.size() == k-1) {
      |        ~~~~~~~~~~^~~~~~
blocks.cpp:58:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 1; i < po.size(); i++) {
      |                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 33 ms 364 KB Output is correct
14 Correct 30 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 33 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 396 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 376 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 138 ms 364 KB Output is correct
15 Correct 139 ms 416 KB Output is correct
16 Correct 133 ms 364 KB Output is correct
17 Correct 140 ms 364 KB Output is correct
18 Correct 146 ms 432 KB Output is correct
19 Correct 152 ms 432 KB Output is correct
20 Correct 136 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 33 ms 364 KB Output is correct
14 Correct 30 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 33 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 396 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 376 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 138 ms 364 KB Output is correct
33 Correct 139 ms 416 KB Output is correct
34 Correct 133 ms 364 KB Output is correct
35 Correct 140 ms 364 KB Output is correct
36 Correct 146 ms 432 KB Output is correct
37 Correct 152 ms 432 KB Output is correct
38 Correct 136 ms 364 KB Output is correct
39 Incorrect 1 ms 364 KB Output isn't correct
40 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 33 ms 364 KB Output is correct
14 Correct 30 ms 512 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 33 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 396 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 376 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 138 ms 364 KB Output is correct
33 Correct 139 ms 416 KB Output is correct
34 Correct 133 ms 364 KB Output is correct
35 Correct 140 ms 364 KB Output is correct
36 Correct 146 ms 432 KB Output is correct
37 Correct 152 ms 432 KB Output is correct
38 Correct 136 ms 364 KB Output is correct
39 Incorrect 1 ms 364 KB Output isn't correct
40 Halted 0 ms 0 KB -