結果

問題 No.929 よくあるボールを移動するやつ
ユーザー karinohitokarinohito
提出日時 2022-06-09 14:23:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 1,587 bytes
コンパイル時間 2,161 ms
コンパイル使用メモリ 203,376 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 04:29:24
合計ジャッジ時間 2,987 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 5 ms
4,348 KB
testcase_08 AC 10 ms
4,348 KB
testcase_09 AC 9 ms
4,348 KB
testcase_10 AC 8 ms
4,348 KB
testcase_11 AC 8 ms
4,348 KB
testcase_12 AC 8 ms
4,348 KB
testcase_13 AC 8 ms
4,348 KB
testcase_14 AC 8 ms
4,348 KB
testcase_15 AC 8 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using vd = vector<double>;
using vvd = vector<vd>;
using vvvd = vector<vvd>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)
using pqr = priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>;

template<class T>
bool chmax(T& p, T q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}
template<class T>
bool chmin(T& p, T q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

ll gcd(ll(a), ll(b)) {
    ll c = a;
    while (a % b != 0) {
        c = a % b;
        a = b;
        b = c;
    }
    return b;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll N;
    cin>>N;
    vll B(N);
    rep(i,N)cin>>B[i];
    ll an=0;
    ll Z=0,F=0;
    rep(i,N){
        if(B[i]==0){
            if(Z!=0){
                Z--;
                an+=i;
            }
            else{
                F++;
                an-=i;
            }
        }
        else if(B[i]>1){
            rep(j,B[i]-1){
                if(F!=0){
                    F--;
                    an+=i;
                }
                else{
                    Z++;
                    an-=i;
                }
            }
        }
    }
    cout<<an<<endl;
    
}
0