Submission #1214793
Source Code Expand
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int lli;
const lli maxn = 16, inf = lli(1e17)+5;
lli A[maxn], maxi[maxn];
int main(void)
{
lli n, k;
scanf("%lld%lld", &n, &k);
for(lli i = 0;i < n;i++) scanf("%lld", &A[i]);
for(lli i = 0;i < n;i++)
{
maxi[i] = max(maxi[i], A[i]);
if(i) maxi[i] = max(maxi[i], maxi[i-1]);
}
lli res = inf;
for(lli mask = 0;mask < (1<<n);mask++)
{
if(__builtin_popcount(mask) == k)
{
lli cost = 0, maxiyet = -1;
for(lli i = 0;i < n;i++)
{
if(mask&(1<<i))
{
lli newht = maxiyet+1;
if(i) newht = max(maxi[i-1]+1, newht);
cost += max(0ll, newht-A[i]);
maxiyet = newht;
}
}
res = min(res, cost);
}
}
printf("%lld\n", res);
}
Submission Info
Submission Time |
|
Task |
B - Buildings are Colorful! |
User |
NibNalin |
Language |
C++14 (GCC 5.4.1) |
Score |
350 |
Code Size |
815 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:15:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld%lld", &n, &k);
^
./Main.cpp:16:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
for(lli i = 0;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 |
|
|
|
|
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 |
1 ms |
256 KB |
sub3_in2.txt |
AC |
1 ms |
256 KB |