結果
問題 | No.929 よくあるボールを移動するやつ |
ユーザー |
|
提出日時 | 2019-11-23 19:40:39 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 13 ms / 2,000 ms |
コード長 | 875 bytes |
コンパイル時間 | 1,678 ms |
コンパイル使用メモリ | 173,076 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-11 07:00:54 |
合計ジャッジ時間 | 2,650 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h>using namespace std::literals::string_literals;using i64 = std::int_fast64_t;using std::cout;using std::cerr;using std::endl;using std::cin;template<typename T>std::vector<T> make_v(size_t a){return std::vector<T>(a);}template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}int main() {int n; scanf("%d", &n); std::vector<int> b(n);for(int i = 0; i < n; i++) scanf("%d", &b[i]);i64 ans = 0;std::stack<int> L, R;for(int i = 0; i < n; i++) {if(b[i] == 1) continue;if(b[i]) {while(!L.empty() and b[i] > 1) {ans += (i - L.top());L.pop();b[i]--;}while(b[i]-- > 1) R.push(i);} else {if(R.empty()) L.push(i);else {ans += (i - R.top());R.pop();}}}printf("%lld\n", ans);return 0;}