Submission #1213040


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll a[16];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll ans = ll(1e18);
	int n,k; cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(int i=0;i<(1<<n);i++)
	{
		if(__builtin_popcount(i)==k)
		{
			ll las = -ll(1e18);
			ll cnt = 0;
			for(int j = 0; j < n; j++)
			{
				if(i&(1<<j))
				{
					if(a[j]>las)
					{
						las=a[j];
						continue;
					}
					cnt+=las+1-a[j];
					las++;
				}
				las=max(las,a[j]);
			}
			ans=min(ans,cnt);
		}
	}
	cout<<ans<<'\n';
}

Submission Info

Submission Time
Task B - Buildings are Colorful!
User zscoder
Language C++14 (GCC 5.4.1)
Score 350
Code Size 1123 Byte
Status AC
Exec Time 1 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 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