結果

問題 No.929 よくあるボールを移動するやつ
ユーザー wacchozwacchoz
提出日時 2019-11-22 22:11:14
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,952 bytes
コンパイル時間 1,163 ms
コンパイル使用メモリ 164,968 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 11:37:28
合計ジャッジ時間 1,876 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
//typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif

 
signed main() {
    int N;
    cin >> N;
    vector<int> B(N);
    priority_queue< int, vector<int>, greater<int> > pq;
    rep(i,N){
        cin >> B[i];
        if(B[i]==0) pq.push(i);
    }
    
    int ans=0;
    rep(i,N){
        if(B[i]>=2){
            rep(k,B[i]-1){
                int t = pq.top(); pq.pop();
                B[i]--;
                B[t]++;
                ans += abs(t-i);
            }
        }
    }
    dump(B);
    cout << ans << endl;
    
    return 0;
}
0