結果
問題 | No.929 よくあるボールを移動するやつ |
ユーザー |
![]() |
提出日時 | 2020-03-14 11:37:03 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 18 ms / 2,000 ms |
コード長 | 493 bytes |
コンパイル時間 | 603 ms |
コンパイル使用メモリ | 78,952 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-23 18:40:37 |
合計ジャッジ時間 | 1,338 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 12 |
ソースコード
#include<iostream>#include<stdio.h>#include<algorithm>#include<vector>#include<string.h>#include<math.h>#include<iomanip>using namespace std;int main(){long n;long count=0,j=0;cin >> n;int a[n],b[n],c[n];for(int i=0;i<n;i++){cin >> a[i];if(a[i] >= 2){b[j]=a[i];c[j]=i;j++;}}j=0;for(int i=0;i<n;i++){if(a[i] == 0){a[i]=1;b[j] -= 1;count += abs(c[j]-i);if(b[j]==1){j++;}}}cout << count << endl;return 0;}