結果

問題 No.929 よくあるボールを移動するやつ
ユーザー mmn15277198mmn15277198
提出日時 2020-03-14 11:37:03
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 78,268 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-15 11:41:57
合計ジャッジ時間 1,601 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#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;
}
0