結果

問題 No.929 よくあるボールを移動するやつ
ユーザー ajiruajiruajiruajiru
提出日時 2020-02-13 03:34:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 529 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 68,468 KB
実行使用メモリ 10,624 KB
最終ジャッジ日時 2024-04-15 05:43:05
合計ジャッジ時間 15,538 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
10,624 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 272 ms
5,376 KB
testcase_08 AC 1,517 ms
5,376 KB
testcase_09 AC 1,539 ms
5,376 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<int> b(n);
	for (int i = 0; i < n; ++i) cin >> b[i];
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		if (b[i] == 0) {
			for (int j = 0; j < i; ++j) {
				if (b[j] > 1) {
					--b[j], ++b[i];
					ans += i - j;
					break;
				}
			}
			if (b[i] == 0) {
				for (int j = i + 1; j < n; ++j) {
					if (b[j] > 0) {
						--b[j], ++b[i];
						ans += j - i;
						break;
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
0