Submission #1213239
Source Code Expand
//見えてほしい建物を決め打ちO(2^n)したとき, 左の建物から高さを決めていくことができる。 //左から見る。最初の建物はその高さがよい。見える建物について、高さをhにしてよいのならh以下にすべき。 #include <iostream> #include <vector> #include <algorithm> #define int long long using namespace std; int n, k; int a[15]; int ma[15]; signed main() { int i, j, l; cin >> n >> k; if (k <= 1) { cout << 0 << endl; return 0; } for (i = 0; i < n; i++) cin >> a[i]; ma[0] = a[0]; for (i = 1; i < n; i++) ma[i] = max(a[i], ma[i - 1]); int ans = 1145141919810; for (i = 0; i < (1 << n); i++) { vector<int> ids; for (j = 0; j < n; j++) { if ((i >> j) % 2) { ids.push_back(j); } } if (ids.size() < k) { continue; } int maxHigh = 0; int sumCost = 0; for (j = 0; j < ids.size(); j++) { int high = max(ma[ids[j]], maxHigh + 1); maxHigh = high; sumCost += high - a[ids[j]]; } ans = min(ans, sumCost); } cout << ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Buildings are Colorful! |
User | startcpp |
Language | C++14 (GCC 5.4.1) |
Score | 350 |
Code Size | 1105 Byte |
Status | AC |
Exec Time | 11 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 | 11 ms | 256 KB |
sub1_in2.txt | AC | 11 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 | 11 ms | 256 KB |
sub3_in2.txt | AC | 11 ms | 256 KB |