結果

問題 No.929 よくあるボールを移動するやつ
ユーザー YamaKasaYamaKasa
提出日時 2019-11-30 00:02:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,203 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 168,256 KB
実行使用メモリ 4,512 KB
最終ジャッジ日時 2023-08-13 06:55:16
合計ジャッジ時間 2,806 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    int B[N];
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }
    vector<int> a;
    for (int i = 0; i < N; i++) {
        if (B[i] > 1) {
            a.push_back(i);
        }
    }
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (B[i] != 0) continue;
        int l = -1;
        int r = a.size();
        int m1 = (2 * l + r) / 3;
        int m2 = (l + 2 * r) / 3;
        int f1 = abs(i - a[m1]);
        int f2 = abs(i - a[m2]);
        while (r - l > 3) {
            m1 = (2 * l + r) / 3;
            m2 = (l + 2 * r) / 3;
            f1 = abs(i - a[m1]);
            f2 = abs(i - a[m2]);
            if (f1 <= f2) {
                r = m2;
            } else {
                l = m1;
            }
        }
        if (f1 <= f2) {
            ans += f1;
            B[m1]--;
            if (B[m1] == 1) {
                a.erase(a.begin() + m1);
            }
        } else {
            ans += f2;
            B[m2]--;
            if (B[m2] == 1) {
                a.erase(a.begin() + m2);
            }
        }
    }
    cout << ans << "\n";
    return 0;
}
0