結果

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

ソースコード

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))

int res = 1 << 30;
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]);
        }
        int tmp = 0;
        REP(i, N) {
            auto itr = st.lower_bound(make_pair(i, 0));
            pair<int, int> p = *itr;    p.second--;
            tmp += abs(p.first - i);
            if (p.second) 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]);
        }
        int tmp = 0;
        REP(i, N) {
            auto itr = st.lower_bound(make_pair(i, 0));
            pair<int, int> p = *itr;    p.second--;
            tmp += abs(p.first - i);
            if (p.second) st.emplace(p);
        }
        res = min(res, tmp);
    }

    cout << res << endl;

}
0