結果

問題 No.929 よくあるボールを移動するやつ
ユーザー もりをもりを
提出日時 2019-11-22 21:46:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,307 bytes
コンパイル時間 1,529 ms
コンパイル使用メモリ 173,268 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 10:55:58
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
using ui64 = uint_fast64_t;
#define REP(i, n) for (i64 (i) = 0; (i) < (n); ++(i))
#define FOR(i, a, b) for (i64 (i) = (a); (i) < (b); ++(i))

i64 res = 1LL << 60;
int N;
vector<int> B;

signed main() {

    cin >> N;
    B.resize(N);
    REP(i, N) cin >> B[i];

    {
        set<pair<int, int>> st;
        REP(i, N) {
            if (B[i]) st.emplace(i, B[i]);
        }
        i64 tmp = 0;
        REP(i, N) {
            auto itr = st.lower_bound(make_pair(i, 0));
            if (itr == st.end()) itr = prev(itr);
            pair<int, int> p = *itr;    p.second--;
            st.erase(itr);
            tmp += abs(p.first - i);
            if (p.second > 0) st.emplace(p);
        }
        res = min(res, tmp);
    }

    {
        set<pair<int, int>> st;
        REP(i, N) {
            if (B[N - 1 - i]) st.emplace(i, B[N - 1 - i]);
        }
        i64 tmp = 0;
        REP(i, N) {
            auto itr = st.lower_bound(make_pair(i, 0));
            if (itr == st.end()) itr = prev(itr);
            pair<int, int> p = *itr;    p.second--;
            st.erase(itr);
            tmp += abs(p.first - i);
            if (p.second > 0) st.emplace(p);
        }
        res = min(res, tmp);
    }

    cout << res << endl;

}
0