Submission #1213408


Source Code Expand

#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e15;


int main(){
	//ios_base::sync_with_stdio(0);
	ll N, K, ans=INF;
	ll a[20];

	cin >> N >> K;
	rep(i,N) cin >> a[i];

	rep(i,1<<N){
		ll cnt = 0, mx = 0, sum = 0;
		rep(k,N){
			if( (1<<k)&i ){
				cnt++;
				sum += max<ll>(0, mx-a[k]);
				mx = max(mx, a[k]) + 1;
			}else if( cnt < K && a[k] > mx ){
				cnt += 100;
				break;
			}
		}
		if( cnt == K ) chmin(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User oyas
Language C++14 (GCC 5.4.1)
Score 350
Code Size 1247 Byte
Status AC
Exec Time 2 ms
Memory 256 KB

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 256 KB
sub0_in2.txt AC 1 ms 256 KB
sub1_in1.txt AC 1 ms 256 KB
sub1_in2.txt AC 2 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 2 ms 256 KB
sub3_in2.txt AC 2 ms 256 KB