結果

問題 No.929 よくあるボールを移動するやつ
ユーザー yakkiyakki
提出日時 2019-11-22 22:18:19
言語 C++11
(gcc 11.4.0)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,088 bytes
コンパイル時間 993 ms
コンパイル使用メモリ 93,040 KB
実行使用メモリ 8,540 KB
最終ジャッジ日時 2023-08-01 12:12:12
合計ジャッジ時間 3,590 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int N; cin >> N;
    vector<int> B(N);
    rep(i,N) cin >> B[i];
    set<int> st;
    rep(i,N){
        if(B[i] == 0) st.insert(i);
    }
    ll ans = 0;
    rep(i,N){
        if(B[i] > 1){
            int d = B[i]-1;
            int cnt = 0;
            for(int u : st){
                ans += abs(i-u);
                cnt++;
                st.erase(u);
                if(cnt == d) break;
            }
        }
    }
    cout << ans << endl;
}

0