結果

問題 No.929 よくあるボールを移動するやつ
ユーザー cotton_fn_cotton_fn_
提出日時 2020-02-02 21:14:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 961 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 123,212 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 01:27:43
合計ジャッジ時間 2,027 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 9 ms
4,348 KB
testcase_08 AC 20 ms
4,348 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 18 ms
4,348 KB
testcase_11 AC 18 ms
4,348 KB
testcase_12 AC 18 ms
4,348 KB
testcase_13 AC 18 ms
4,348 KB
testcase_14 AC 18 ms
4,348 KB
testcase_15 AC 17 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int absi(int x) {
    return max(x, -x);
}
int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    i64 ans = 0;
    for (int i = 0, j = 0; i < n && j < n; ) {
        while (i < n && b[i] > 0) ++i;
        while (j < n && b[j] < 2) ++j;
        if (i < n && j < n) {
            b[j]--;
            b[i]++;
            ans += absi(i - j);
        }
    }
    for (int i = 0; i < n; ++i) {
        assert(b[i] == 1);
    }
    cout << ans << endl;
    return 0;
}
0