Submission #1213166


Source Code Expand

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N,K;
int a[22];

int main(){
	scanf("%d%d" , &N , &K);
	repp(i,0,N){
		scanf("%d" , a + i);
	}
	LL ans = 1234567890123456;
	repp(i,1,1<<N){
		int x = 0;
		for(int z = i ; z > 0 ; z /= 2) if(z%2==1) ++x;
		if(x < K) continue;
		x = 0;
		LL y = 0;
		int p = i;
		repp(j,0,N){
			if(x < a[j]){
				x = a[j];
			} else if(p%2==1){
				y += x - a[j] + 1;
				++x;
			}
			p /= 2;
		}
		ans = min(ans , y);
	}
	printf("%lld\n" , ans);
	return 0;
}

Submission Info

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

Compile Error

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