結果
| 問題 |
No.929 よくあるボールを移動するやつ
|
| コンテスト | |
| ユーザー |
misora192
|
| 提出日時 | 2020-04-29 11:35:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 700 bytes |
| コンパイル時間 | 1,718 ms |
| コンパイル使用メモリ | 172,180 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 23:00:47 |
| 合計ジャッジ時間 | 2,734 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<ll> b(n);
rep(i, n) cin >> b[i];
queue<int> zero;
queue<int> pos;
ll ans = 0;
rep(i, n){
if(b[i] == 0){
if(!pos.empty()){
int j = pos.front();
pos.pop();
ans += abs(j - i);
}else{
zero.push(i);
}
}else if(b[i] >= 2){
rep(_, b[i] - 1){
if(!zero.empty()){
int j = zero.front();
zero.pop();
ans += abs(j - i);
}else{
pos.push(i);
}
}
}
}
assert(zero.empty() && pos.empty());
cout << ans << endl;
}
misora192