Submission #1216719


Source Code Expand

#include<stdio.h>
#include<limits.h>
#define ll long long
ll a[20],cost=0,ans=LLONG_MAX,k,n,i;
ll min1(ll a,ll b){
	if(a<b)
		return a;
	else
		return b;
}
void match(ll b,ll s,ll e){
	if(b==n){
		if(s>=k){
			ans=min1(ans,cost);
		}
		return ;
	}
	if(a[b]>e){
		match(b+1,s+1,a[b]);
	}
	else{
		match(b+1,s,e);
		cost+=(e+1-a[b]);
		match(b+1,s+1,e+1);
		cost-=(e+1-a[b]);
	}
}
int main(){
	scanf("%lld%lld",&n,&k);
	for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
	match(1,1,a[0]);
	printf("%lld\n",ans);
	return 0;
} 

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:29:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&n,&k);
                         ^
./Main.cpp:31:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   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