結果
問題 | No.929 よくあるボールを移動するやつ |
ユーザー |
|
提出日時 | 2019-11-23 15:10:39 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 12 ms / 2,000 ms |
コード長 | 630 bytes |
コンパイル時間 | 2,368 ms |
コンパイル使用メモリ | 192,768 KB |
最終ジャッジ日時 | 2025-01-08 05:31:13 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;signed main() {ios::sync_with_stdio(false); cin.tie(0);int n;cin >> n;vector<int> b(n);for (int i = 0; i < n; i++) {cin >> b[i];}int l = 0, r = 0;long long ans = 0;for (int i = 0; i < n; i++) {if (b[i] > 1) {b[i]--;} else {while (b[l] == 0 && l < i) l++;if (b[l] > 0) {ans += i - l;b[l]--;continue;}while (b[r] == 0 && r < n) r++;if (r < n && b[r] > 0) {ans += r - i;b[r]--;}}}cout << ans << '\n';return 0;}