Submission #2549611
Source Code Expand
#include <bits/stdc++.h> using namespace std; int n, k; vector<int> a; map<tuple<int, int, int>, long long> dp; long long dfs(int now, int maxheight, int selected) { if (selected == k) return 0; if (now == n) return numeric_limits<long long>::max(); auto status = make_tuple(now, maxheight, selected); if (dp.count(status)) return dp[status]; if (maxheight < a[now]) { return dp[status] = dfs(now + 1, a[now], selected + 1); } long long res = dfs(now + 1, maxheight, selected); long long res2 = dfs(now + 1, maxheight + 1, selected + 1); if (res2 != numeric_limits<long long>::max()) { res2 += maxheight + 1 - a[now]; } res = min(res, res2); return dp[status] = res; } void hawawa() { cin >> n >> k; a.resize(n); for (auto&& i : a) { cin >> i; } cout << dfs(1, a[0], 1) << "\n"; } int main() { ios::sync_with_stdio(false); cin.tie(0); hawawa(); return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Buildings are Colorful! |
User | stone725 |
Language | C++14 (GCC 5.4.1) |
Score | 350 |
Code Size | 931 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 |