Submission #1213511


Source Code Expand

#include<stdio.h>

long long pow2(long long x){
	long long r=1;
	while(x!=0){r*=2;x--;}
	return r;
}

long long bc(long long x){
	long long r=0;
	while(x!=0){r+=(x%2);x/=2;}
	return r;
}

long long calc(long long d,long long x[]){
	long long r = 0,i,m;
	m = x[1];d/=2;
	for(i = 2;i <= 15;i++){
		if(d%2){
			if(m < x[i]){m = x[i];}
			else{r+=(m+1-x[i]);m++;}
		}
		else if(d != 0 && m < x[i]){return 1145141919810;}
		d/=2;
	}
	return r;
}

int main(){
	long long n,k,a[16],i,m=1145141919810,x;
	scanf("%lld%lld",&n,&k);
	for(i = 1;i <= n;i++){scanf("%lld",&a[i]);}
	for(i = 1;i < pow2(n);i+=2){
		if(bc(i) != k){continue;}
		x = calc(i,a);
		if(x < m){m = x;}
	}
	printf("%lld\n",m);
	return 0;
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User physics0523
Language C (GCC 5.4.1)
Score 350
Code Size 737 Byte
Status AC
Exec Time 1 ms
Memory 128 KB

Compile Error

./Main.c: In function ‘main’:
./Main.c:31:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&k);
  ^
./Main.c:32:24: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
  for(i = 1;i <= n;i++){scanf("%lld",&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 1 ms 128 KB
sub1_in2.txt AC 1 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 1 ms 128 KB
sub3_in2.txt AC 1 ms 128 KB