답안 #91325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91325 2018-12-27T06:16:50 Z YottaByte K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1000 ms 8724 KB
#include <stdio.h>
#include <iomanip>
#include <vector>
using namespace std;

const int N = 102;

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


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

void bld(int v = 1, int l = 1, int r = n)
{
	if(l == r)
	{
		t[v] = a[l];
		return;
	}
	else
	{
		int mid = l + r >> 1ll;
		bld(v + v, l, mid);
		bld(v + v + 1, mid + 1, r);
	}
	t[v] = max(t[v + v], t[v + v + 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));
}

main()
{
	scanf("%lld %lld", &n, &k);
	for(int i = 1; i <= n; i++)
		scanf("%lld", &a[i]);
	
	bld();
	
	for(int i = 1; i <= k; i++)
	{
		for(int l = 1; l <= n; l++)
		{
			for(int r = 1; r <= n; r++)
			{
				b[i][l][r] = 1e9;
			}
		}
	}
	
	for(int l = 1; l <= n - k + 1; l++)
	{
		for(int r = l; r <= n; r++)
		{
			b[1][l][r] = getmx(l, r);
		}
	}
	
	for(int i = 2; i <= k; i++)
	{
		for(int l = i; l <= n; l++)
		{
			for(int r = l; r <= n; r++)
			{
				for(int j = 1; j < l; j++)
				{
					b[i][l][r] = min(b[i - 1][j][l - 1], b[i][l][r]);
				}
				b[i][l][r] += getmx(l, r);
			}
		}
	}
	
	for(int l = k; l <= n; l++)
	{
		ans = min(ans, b[k][l][n]);
	}
	
	printf("%lld\n", ans);
}
/**

5 3
1 2 3 4 5

100 50
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10

**/

Compilation message

blocks.cpp: In function 'void bld(long long int, long long int, long long int)':
blocks.cpp:29: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:41:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1ll;
            ~~^~~
blocks.cpp: At global scope:
blocks.cpp:45:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main()
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:47: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:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &a[i]);
   ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Incorrect 2 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 448 KB Output is correct
2 Incorrect 2 ms 448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 4484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1037 ms 8724 KB Time limit exceeded
2 Halted 0 ms 0 KB -