結果

問題 No.77 レンガのピラミッド
ユーザー 👑 tatt61880tatt61880
提出日時 2019-03-29 02:10:20
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 961 bytes
コンパイル時間 2,042 ms
コンパイル使用メモリ 159,664 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-14 15:34:36
合計ジャッジ時間 3,067 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 2 ms
4,352 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,356 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 1 ms
4,352 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,356 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,352 KB
testcase_18 AC 2 ms
4,352 KB
testcase_19 AC 1 ms
4,352 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 1 ms
4,352 KB
testcase_24 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var N: int :: cui@input().toInt(&)
	var _: [][]char :: cui@input().split(" ")
	var A: []int :: #[2 * N]int
	for i(0, N - 1)
		do A[i] :: _[i].toInt(&)
	end for
	var ans: int :: 10000
	for c(0, 2 * N - 1)
		var r: int :: 2 * c
		if(r > 2 * N - 1)
			break c
		end if
		do ans :: [ans, f(A, c, r)].min()
	end for
	do cui@print("\{ans}\n")
	func f(A: []int, center: int, right: int): int
		var plus: int
		var minus: int
		for i(0, ^A - 1)
			if(i <= center)
				var targetVal: int :: i + 1
				if(A[i] > targetVal)
					do plus :+ A[i] - targetVal
				elif(A[i] < targetVal)
					do minus :+ targetVal - A[i]
				end if
			elif(center < i & i <= right)
				var targetVal: int :: right - i + 1
				if(A[i] > targetVal)
					do plus :+ A[i] - targetVal
				elif(A[i] < targetVal)
					do minus :+ targetVal - A[i]
				end if
			else
				do plus :+ A[i]
			end if
		end for
		if(plus >= minus)
			ret plus
		else
			ret 10000
		end if
	end func
end func
0