Submission #1213105


Source Code Expand

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int main() {
	int n, k;
	ll a[15];
	
	cin >> n >> k;
	REP(i, n) scanf("%lld", a + i);
	
	ll ans = INF;
	
	REP(s, 1<<n) {
		int cnt = 0;
		REP(i, n) if (s >> i & 1) cnt++;
		
		if (cnt < k) continue;
		
		ll cost = 0;
		ll last = 0;
		
		REP(i, n) {
			
			ll now = a[i];
			
			if (s >> i & 1) {
				if (last >= a[i]) {
					cost += last - a[i] + 1;
					now += last - a[i] + 1;
				}
			}
			chmax(last, now);
		}
		
		chmin(ans, cost);
	}
	
	cout << ans << endl;
	
	return 0;
}

Submission Info

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

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:41:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  REP(i, n) scanf("%lld", 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 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