結果

問題 No.1279 Array Battle
ユーザー 👑 tatt61880tatt61880
提出日時 2021-07-06 21:43:19
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 150,988 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-10-14 18:35:30
合計ジャッジ時間 4,406 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var a: []int :: #[n]int
	for i(0, n - 1)
		do a[i] :: cui@inputInt()
	end for
	var b: []int :: #[n]int
	for i(0, n - 1)
		do b[i] :: cui@inputInt()
	end for
	
	var idxs: []int :: lib@range(0, n - 1, 1)
	
	var maxScore: int :: -1
	var cnt: int :: 0
	while(nextPermutation(idxs), skip)
		var score: int :: 0
		for i(0, n - 1)
			if(a[idxs[i]] > b[i])
				do score :+ a[idxs[i]] - b[i]
			end if
		end for
		
		if(score = maxScore)
			do cnt :+ 1
		elif(score > maxScore)
			do maxScore :: score
			do cnt :: 1
		end if
	end while
	
	var ans: int :: cnt
	do cui@print("\{ans}\n")
	
	func nextPermutation(arr: []int): bool
		var len: int :: ^arr
		var left: int :: len - 2
		while(left >= 0 & arr[left] >= arr[left + 1])
			do left :- 1
		end while
		if(left < 0)
			ret false
		end if
		var right: int :: len - 1
		while(arr[left] >= arr[right])
			do right :- 1
		end while
		var tmp: int :: arr[left]
		do arr[left] :: arr[right]
		do arr[right] :: tmp
		do left :+ 1
		do right :: len - 1
		while(left < right)
			do tmp :: arr[left]
			do arr[left] :: arr[right]
			do arr[right] :: tmp
			do left :+ 1
			do right :- 1
		end while
		ret true
	end func
end func
0