結果

問題 No.929 よくあるボールを移動するやつ
ユーザー uryo1903uryo1903
提出日時 2019-11-22 21:59:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 16 ms / 2,000 ms
コード長 1,244 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 173,204 KB
実行使用メモリ 4,612 KB
最終ジャッジ日時 2023-08-01 11:47:11
合計ジャッジ時間 2,820 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int long long
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
 
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> b(n);
	min_heap<pii> que;
	rep(i,n){
		cin >> b[i];
		if(b[i] > 1) que.emplace(i,b[i]);
	}
	int cnt = 0;
	rep(i,n){
		if(b[i] == 0){
			pii x = que.top();
			que.pop();
			cnt += abs(i - x.first);
			x.second--;
			if(x.second > 1) que.emplace(x);
		}
	}
	cout << cnt << '\n';
	return 0;
}

0