Submission #1214128
Source Code Expand
#include <bits/stdc++.h> using namespace std; int main() { int n,k; scanf("%d%d", &n, &k); int arr[n]; for (int i=0; i<n; i++) scanf("%d", &arr[i]); long long ans=LLONG_MAX; for (int i=0; i<(1<<(n+1)); i++) { int num=0; long long tot=0; int prev=0; for (int j=0; j<n; j++) { if (1<<j & i) { num++; tot+=max(prev+1-arr[j],0); prev=max(prev+1,arr[j]); } prev=max(prev,arr[j]); } if (num==k) ans=min(ans,tot); } printf("%lld\n", ans); }
Submission Info
Submission Time | |
---|---|
Task | B - Buildings are Colorful! |
User | estelle0500 |
Language | C++14 (GCC 5.4.1) |
Score | 350 |
Code Size | 501 Byte |
Status | AC |
Exec Time | 5 ms |
Memory | 256 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:6:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &n, &k); ^ ./Main.cpp:8:46: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] for (int i=0; i<n; i++) scanf("%d", &arr[i]); ^
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | Subtask3 | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 120 / 120 | 90 / 90 | 140 / 140 | ||||||||
Status |
|
|
|
|
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 | 5 ms | 256 KB |
sub1_in2.txt | AC | 5 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 | 5 ms | 256 KB |
sub3_in2.txt | AC | 5 ms | 256 KB |