Submission #1213066


Source Code Expand

#include <bits/stdc++.h>

#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,a,b) for(int i=(a);i>=(b);i--)

#define LL long long
#define Ldouble long double
#define PI 3.1415926535897932384626

#define PII pair<int,int>
#define PLL pair<LL,LL>
#define mp make_pair
#define fi first
#define se second

using namespace std;

LL res, cur;

int n, k, s[17];

int main(){
	scanf("%d %d", &n, &k);
	FI(i, 1, n) scanf("%d", &s[i]);
	res = (1LL << 44);
	FI(i, 0, (1 << n) - 1){
		int cnt = 0;
		FI(j, 0, n - 1) if(i & (1 << j)) cnt++;
		if(cnt == k){
			cur = 0;
			int necess = 0;
			FI(j, 0, n - 1){
				if(i & (1 << j)){
					if(s[j + 1] <= necess){
						necess++;
						cur += necess - s[j + 1];
					}
					else necess = s[j + 1];
				}
				else necess = max(necess, s[j + 1]);
			}
			res = min(res, cur);
		}
	}
	printf("%lld\n", res);
	return 0;
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User alex20030190
Language C++14 (GCC 5.4.1)
Score 350
Code Size 901 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:23:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &k);
                        ^
./Main.cpp:24:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  FI(i, 1, n) scanf("%d", &s[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 256 KB
sub0_in2.txt AC 1 ms 256 KB
sub1_in1.txt AC 2 ms 256 KB
sub1_in2.txt AC 2 ms 256 KB
sub2_in1.txt AC 1 ms 256 KB
sub2_in2.txt AC 1 ms 256 KB
sub2_in3.txt AC 1 ms 256 KB
sub3_in1.txt AC 2 ms 256 KB
sub3_in2.txt AC 2 ms 256 KB