Submission #1218149
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS #include <algorithm> #include <bitset> #include <climits> #include <cstdio> #include <vector> using namespace std; int main() { int N, K; if (scanf("%d%d", &N, &K) < 2) return 0; vector<int> a(N); for (int i = 0; i < N; i++) if (scanf("%d", &a[i]) < 1) return 0; long long ans = LLONG_MAX; for (int i = 0; i < (1 << N); i++) { // 最大で15個の建物 bitset<15> bs(i); if (bs.count() != K) continue; // ビットが立っている数がKならば long long cost = 0; int h = 0; for (int i = 0; i < N; i++) { // 見えていたい建物 if (bs[i]) { // 史上最高保持 h = max(a[i], h + 1); // コスト足し込み 自分が史上最高ならゼロ cost += h - a[i]; } // 史上最高保持 else h = max(a[i], h); } // 最小コスト保持 ans = min(ans, cost); } printf("%lld\n", ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Buildings are Colorful! |
User | ShinjiSHIBATA |
Language | C++14 (GCC 5.4.1) |
Score | 350 |
Code Size | 1161 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 |
|
|
|
|
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 |