結果

問題 No.929 よくあるボールを移動するやつ
ユーザー fine
提出日時 2019-11-22 22:15:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 644 bytes
コンパイル時間 1,801 ms
コンパイル使用メモリ 167,632 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-11 03:55:34
合計ジャッジ時間 2,223 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 4 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> b(n);
    
    int idx = -1;
    for (int i = 0; i < n; i++) {
        cin >> b[i];
        if (b[i] != 0 && idx == -1) {
            idx = i;
        }
    }

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        ans += abs(idx - i);
        b[idx]--;
        if (b[idx] == 0) {
            while (++idx < n) {
                if (b[idx] > 0) break;
            }
        }
        b[i]++;
        if (idx == n) break;
    }
    cout << ans << "\n";
    return 0;
}
0