Submission #1438859


Source Code Expand

#include <iostream>
#include <vector>
#include <algorithm>
 
#define rep(i, n) for(int i = 0; i < (n); ++i)
 
using namespace std;

typedef long long ll;

const ll inf = 1e11;

int n, k;
int a[15];

ll calc(int f){
    int s = 0;
    ll c = 0;
    rep(i, n){
        if(f >> i & 1 && a[i] <= s){
            ++s;
            c += s - a[i];
        }
        else{
            s = max(a[i], s);
        }
    }
    return c;
}

int main(){
    cin >> n >> k;
    rep(i, n){
        cin >> a[i];
    }

    ll ans = inf;
    rep(i, 1 << n){
        int c = 0;
        rep(j, n){
            c += i >> j & 1;
        }
        if(c >= k){
            ans = min(calc(i), ans);
        }
    }
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User hipokaba
Language C++14 (GCC 5.4.1)
Score 350
Code Size 777 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 2 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