Submission #1213244


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <cstring>

#define maxn 20
int a[maxn], b[maxn];
typedef long long ll;
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
int main()
{
	int n, k; scanf("%d%d", &n, &k);
	ll ans = ~0ULL >> 1;
	for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
	for (int S = 0, _ = 1 << n; S < _; ++S)
	{
		memcpy(b, a, n << 2);
		int cnt = 0;
		ll cost = 0, maxx = -0x7fffffff;
		for (int i = 0; i < n; ++i)
		{
			if ((S & (1 << i)) && b[i] <= maxx)
				cost += maxx - b[i] + 1, b[i] = maxx + 1;
			cmax(maxx, b[i]) ? ++cnt : 0;
		}
		cnt >= k ? cmin(ans, cost) : 0;
	}
	printf("%lld\n", ans);
	return 0;
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User chentong
Language C++14 (GCC 5.4.1)
Score 350
Code Size 711 Byte
Status AC
Exec Time 3 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:12:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  int n, k; scanf("%d%d", &n, &k);
                                 ^
./Main.cpp:14:48: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
                                                ^

Judge Result

Set Name Sample Subtask1 Subtask2 Subtask3
Score / Max Score 0 / 0 120 / 120 90 / 90 140 / 140
Status
AC × 2
AC × 2
AC × 3
AC × 9
Set Name Test Cases
Sample sub0_in1.txt, sub0_in2.txt
Subtask1 sub1_in1.txt, sub1_in2.txt
Subtask2 sub2_in1.txt, sub2_in2.txt, sub2_in3.txt
Subtask3 sub0_in1.txt, sub0_in2.txt, sub1_in1.txt, sub1_in2.txt, sub2_in1.txt, sub2_in2.txt, sub2_in3.txt, sub3_in1.txt, sub3_in2.txt
Case Name Status Exec Time Memory
sub0_in1.txt AC 1 ms 128 KB
sub0_in2.txt AC 1 ms 128 KB
sub1_in1.txt AC 3 ms 128 KB
sub1_in2.txt AC 2 ms 128 KB
sub2_in1.txt AC 1 ms 128 KB
sub2_in2.txt AC 1 ms 128 KB
sub2_in3.txt AC 1 ms 128 KB
sub3_in1.txt AC 3 ms 128 KB
sub3_in2.txt AC 3 ms 128 KB