ソースコード 拡げる

Copy
```#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
int N;
long long K;
scanf("%d%lld", &N, &K);
vector<long long> A(N+1);
for(int i = 0; i < N; ++i) {
scanf("%lld", &A[i]);
--A[i];
}
long long current_count = -1;
{
long long current_height = 0;
for(auto x : A) {
current_count += abs(current_height - x);
current_count += 3 + 2 * x;
current_height = x;
}
}
A[N] = 0;
vector<pair<long long,int>> st; st.reserve(N+2);
vector<pair<int,long long>> parts; parts.reserve(N+2);
st.emplace_back(0, 0);
for(int i = 0; i <= N; ++i) {
while(st.back().first > A[i]) {
auto x = st.back(); st.pop_back();
parts.emplace_back(x.second, x.first-max(A[i], st.back().first));
st.back().second += x.second;
}
if(st.back().first == A[i]) {
st.back().second += 1;
} else {
st.emplace_back(A[i], 1);
}
}
sort(parts.begin(), parts.end());
long long Krem = K;
for(auto part : parts) {
if(Krem >= part.first * part.second) {
fprintf(stderr, "consume: %d * %lld\n", part.first, part.second);
current_count -= (part.first * 2 + 2) * part.second;
Krem -= part.first * part.second;
} else {
long long consum1 = Krem / part.first;
fprintf(stderr, "consume: %d * %lld\n", part.first, consum1);
current_count -= (part.first * 2 + 2) * consum1;
Krem -= part.first * consum1;
fprintf(stderr, "consume: (%d)\n", (int)Krem);
current_count -= (Krem * 2);
Krem = 0;
break;
}
}
printf("%lld\n", current_count);
return 0;
}
```

#### 提出情報

提出日時 2015-11-15 09:57:39+0900 B - 立方体とペンキ qnighy C++11 (GCC 4.9.2) 0 1692 Byte WA 236 ms 4648 KB

#### コンパイルエラー

```./Main.cpp: In function ‘int main()’:
./Main.cpp:9:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%lld", &N, &K);
^
./Main.cpp:12:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &A[i]);
^
```

#### ジャッジ結果

セット名 Sample All

 AC × 2
 AC × 11 WA × 8
セット名 テストケース
Sample sample-01.txt, sample-02.txt
All sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt
ケース名 結果 実行時間 メモリ
01-01.txt AC 24 ms 744 KB
01-02.txt AC 27 ms 800 KB
01-03.txt WA 236 ms 3108 KB
01-04.txt WA 202 ms 3108 KB
01-05.txt WA 211 ms 3104 KB
01-06.txt WA 215 ms 3108 KB
01-07.txt AC 68 ms 3108 KB
01-08.txt AC 47 ms 1688 KB
01-09.txt AC 48 ms 1576 KB
01-10.txt AC 49 ms 1564 KB
01-11.txt AC 49 ms 1684 KB
01-12.txt AC 128 ms 4640 KB
01-13.txt AC 175 ms 4648 KB
01-14.txt WA 208 ms 3104 KB
01-15.txt WA 211 ms 3116 KB
01-16.txt WA 209 ms 3876 KB
01-17.txt WA 213 ms 3880 KB
sample-01.txt AC 23 ms 800 KB
sample-02.txt AC 24 ms 920 KB