Submission #170402

# Submission time Handle Problem Language Result Execution time Memory
170402 2019-12-25T04:11:01 Z Lightning K blocks (IZhO14_blocks) C++14
18 / 100
1000 ms 504 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
 
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
 
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define pb push_back
#define ppb pop_back
#define mkp make_pair
#define F first
#define S second
#define show(a) cerr << #a <<" -> "<< a <<"\n"
#define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d))
#define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d))
//#define int ll
 
const int N = 205;
const int INF = 2e9 + 5;
 
int n, k, a[N], ans = INF;
bool End[N];
 
void rec(int pos, int cnt) {
	if(pos == n) {
		if(cnt != k - 1) return;
		int mx = 0;
		int sum = 0;
		for(int i = 1; i <= n; ++i) {
			mx = max(mx, a[i]);
			if(End[i]) {
				sum += mx;
				mx = 0;
			}
		}
		ans = min(ans, sum);
		return;
	}
	if(n - pos + cnt > k - 1 - cnt) {
		rec(pos + 1, cnt);
	}
	if(cnt == k - 1) return;
	if(cnt + 1 + n - pos >= k - 1) {
		End[pos] = 1;
		rec(pos + 1, cnt + 1);
		End[pos] = 0;
	}
}
 
int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> k;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
	}
	End[n] = 1;
	rec(1, 0);
	cout << ans;
	return 0;
}
 
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 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 380 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 Execution timed out 1016 ms 476 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 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 380 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 11 ms 376 KB Output is correct
15 Correct 12 ms 376 KB Output is correct
16 Correct 4 ms 376 KB Output is correct
17 Correct 4 ms 376 KB Output is correct
18 Correct 11 ms 376 KB Output is correct
19 Correct 4 ms 252 KB Output is correct
20 Correct 2 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1068 ms 376 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -