Submission #2874976


Source Code Expand

#include<cstdio>
#include<cstring>
using namespace std;
	int n,k;
	long long ans;
	long long a[16];
void dfs(int now,long long fee)
{
	if (fee>=ans)
		return;
	int x=0;
	int last=0;
	for (int i=1;i<=n;i++)
		if (a[i]>a[last])
		{
			x++;
			last=i;
		}
	if (x==k)
	{
		if (fee<ans) ans=fee;
		return;
	}
	last=0;
	for (int i=1;i<now;i++)
		if (a[i]>a[last])
			last=i;
	for (int i=now;i<=n;i++)
	{
		if (a[i]>a[last])
		{
			last=i;
			continue;
		}
		long long b=a[i];
		a[i]=a[last]+1;
		dfs(now+1,fee+a[last]-b+1);
		a[i]=b;
	}
}
int main()
{
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++)
		scanf("%lld",&a[i]);
	if (n==k)
	{
		long long ans=0;
		for (int i=1;i<=n;i++)
			if (a[i]<a[i-1])
			{
				ans+=a[i-1]-a[i]+1;
				a[i]=a[i-1]+1;
			}
		printf("%lld",ans);
		return 0;
	}
	ans=2147483647;
	dfs(1,0);
	printf("%lld",ans);
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User Forward_Star
Language C++14 (GCC 5.4.1)
Score 0
Code Size 893 Byte
Status WA
Exec Time 249 ms
Memory 128 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:43:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&k);
                     ^
./Main.cpp:45: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 0 / 120 0 / 90 0 / 140
Status
WA × 2
WA × 2
WA × 3
WA × 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 WA 1 ms 128 KB
sub0_in2.txt WA 1 ms 128 KB
sub1_in1.txt WA 1 ms 128 KB
sub1_in2.txt WA 1 ms 128 KB
sub2_in1.txt WA 1 ms 128 KB
sub2_in2.txt WA 1 ms 128 KB
sub2_in3.txt WA 1 ms 128 KB
sub3_in1.txt WA 10 ms 128 KB
sub3_in2.txt WA 249 ms 128 KB