Submission #91313

# Submission time Handle Problem Language Result Execution time Memory
91313 2018-12-27T05:02:35 Z YottaByte K blocks (IZhO14_blocks) C++14
0 / 100
515 ms 263168 KB
#include <stdio.h>
#include <iomanip>
#include <vector>
using namespace std;

const int N = 200;

#define pb push_back
#define ll long long
#define int long long
#define fr first
#define sc second
#define mk make_pair

ll ans = 1e8;
int n, a[N + 1], k, t[N * 4];
vector < pair < int, int > > lr[201];

void build(int v = 1, int l = 1, int r = n)
{
	if(l == r)
	{
		t[v] = a[l];
		return;
	}
	else
	{
		int mid = l + r >> 1ll;
		build(v + v, l, mid);
		build(v + v + 1, mid + 1, r);
	}
	t[v] = max(t[v + v], t[v + v + 1]);
}

void brute(int l, int q)
{
	if(q == k)
	{
		//printf("%lld %lld %lld\n\n", q, l, n);
		lr[q].pb( mk( l, n ) );
		return;
	}
	
	if(l == n) return;
	else
	{
		for(int i = l; i <= n - q; i++)
		{
			//printf("%lld %lld %lld\n", q, l, i);
			lr[q].pb( mk( l, i ) );
			brute(i + 1, q + 1);
		}
	}
}

int getmx(int ql, int qr, int v = 1, int l = 1, int r = n)
{
	if(l > qr || ql > r) return 0;
	if(ql <= l && r <= qr)
		return t[v];
	int mid = l + r >> 1ll;
	return max(getmx(ql, qr, v + v, l, mid), getmx(ql, qr, v + v + 1, mid + 1, r));
}

void calc(int cur = 1, ll psum = 0ll, int prel = 0, int prer = 0)
{
	if(cur > k)
	{
		if(ans > psum)
		{
			ans = psum;
			//printf("%lld %lld\n", prel, psum);
		}
		return;
	}
	else
	{
		for(int i = 0; i < lr[cur].size(); i++)
		{
			int l = lr[cur][i].fr;
			if(l <= prer);
			else if(l == prer + 1)
			{
				int r = lr[cur][i].sc;
				//printf("CUR %lld %lld %lld\n", cur, l, r);
				calc(cur + 1, psum + getmx(l, r), l, r); 
			}
			else return;
		}
	}
}

main()
{
	scanf("%lld %lld", &n, &k);
	//scanf("%d %d", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
		//scanf("%d", &a[i]), sum += a[i];
	
	build(  );
	
	brute(1, 1);
	
	calc(  );
	
	//puts("");
	//printf("%lld\n", getmx(3, 5) + getmx(1, 2));
	//puts("");
	
	printf("%lld", ans);
}
/**

5 2
4 5 1 2 3

**/

Compilation message

blocks.cpp: In function 'void build(long long int, long long int, long long int)':
blocks.cpp:28:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int mid = l + r >> 1ll;
             ~~^~~
blocks.cpp: In function 'long long int getmx(long long int, long long int, long long int, long long int, long long int)':
blocks.cpp:61:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1ll;
            ~~^~~
blocks.cpp: In function 'void calc(long long int, long long int, long long int, long long int)':
blocks.cpp:78:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < lr[cur].size(); i++)
                  ~~^~~~~~~~~~~~~~~~
blocks.cpp: At global scope:
blocks.cpp:93:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:95:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld", &n, &k);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
blocks.cpp:98:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 1 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 1 ms 484 KB Output is correct
6 Correct 2 ms 484 KB Output is correct
7 Correct 1 ms 484 KB Output is correct
8 Correct 1 ms 484 KB Output is correct
9 Incorrect 1 ms 484 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 484 KB Output is correct
2 Correct 1 ms 484 KB Output is correct
3 Correct 2 ms 716 KB Output is correct
4 Correct 1 ms 744 KB Output is correct
5 Correct 2 ms 744 KB Output is correct
6 Correct 1 ms 744 KB Output is correct
7 Correct 1 ms 744 KB Output is correct
8 Correct 1 ms 744 KB Output is correct
9 Incorrect 1 ms 744 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 515 ms 263168 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2 ms 263168 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -