Submission #1213093


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n,k;
int a[25];

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d",a+i);
  ll ans = 1e18;
  REP(mask,1<<n){
    if(__builtin_popcount(mask) != k)continue;
    ll tmp = 0;
    int mx = -1;
    REP(i,n){
      if((mask>>i)&1){
        // use this
        if(a[i]<=mx){
          tmp += (mx+1) - a[i];
          mx++;
        }else{
          CHMAX(mx,a[i]);
        }
      }else{
        CHMAX(mx,a[i]);
      }
    }
    CHMIN(ans,tmp);
  }
  printf("%lld\n",ans);
  return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:38:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d",&n,&k);
                      ^
./Main.cpp:39:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   REP(i,n)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 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