Submission #1213042


Source Code Expand

#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;

int n;
int k;

vector<long long int> v;

int cn(int num){
	int r = 0;
	while (num){
		if ((num & 1)){
			r++;
		}
		num >>= 1;
	}
	return r;
}
int main(){
	cin >> n >> k;
	for (int i = 0; i < n; i++){
		int a;
		scanf("%d", &a);
		v.push_back(a);
	}
	long long int ans = LLONG_MAX;
	for (int i = 0; i < (1 << n); i++){
		int val = cn(i);
		if (val != k)continue;
		long long int mx = LLONG_MIN;
		long long int cost = 0;
		for (int j = 0; j < n; j++){
			if ((i >> j) & 1){
				if(mx>=v[j])cost += max(0LL, mx + 1LL - v[j]);
				mx++;
			}
			mx = max(mx, v[j]);
		}
		ans = min(ans, cost);
	}
	printf("%lld\n", ans);
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
                  ^

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 1 ms 256 KB
sub1_in2.txt AC 1 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