結果
| 問題 |
No.929 よくあるボールを移動するやつ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-22 22:48:23 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 18 ms / 2,000 ms |
| コード長 | 785 bytes |
| コンパイル時間 | 1,308 ms |
| コンパイル使用メモリ | 162,888 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 04:24:30 |
| 合計ジャッジ時間 | 2,087 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 12 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n;
cin >> n;
queue<int> que;
int a[100010];
for(int i = 0;i < n;i++){
cin >> a[i];
}
int ans = 0;
int next = 0;
for(int i = 0;i < n;i++){
if(next > 0){
ans += next;
}
if(a[i] != 0){
while(a[i] > 1){
if(que.size() == 0){
break;
}
a[i]--;
ans += i - que.front();
que.pop();
}
next += a[i]-1;
}else{
if(next > 0){
next--;
}else{
que.push(i);
}
}
}
cout << ans << endl;
return 0;
}