結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 tatt61880tatt61880
提出日時 2021-07-30 21:25:54
言語 Kuin
(KuinC++ v.2021.9.17)
結果
WA  
実行時間 -
コード長 1,773 bytes
コンパイル時間 2,398 ms
コンパイル使用メモリ 154,972 KB
実行使用メモリ 6,528 KB
最終ジャッジ日時 2023-10-14 18:38:43
合計ジャッジ時間 6,726 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 3 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 3 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 2 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 WA -
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 181 ms
6,352 KB
testcase_17 AC 183 ms
6,420 KB
testcase_18 AC 183 ms
6,500 KB
testcase_19 WA -
testcase_20 AC 174 ms
6,244 KB
testcase_21 AC 175 ms
6,424 KB
testcase_22 AC 418 ms
5,852 KB
testcase_23 AC 9 ms
5,676 KB
testcase_24 AC 144 ms
6,036 KB
testcase_25 AC 11 ms
5,788 KB
testcase_26 AC 178 ms
6,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

func main()
	var n: int :: cui@inputInt()
	var k: []char :: cui@input()
	var a: []int :: #[10]int
	for i(1, 9)
		do a[i] :: cui@inputInt()
	end for
	
	if(n < ^k)
		do cui@print("-1\n")
		ret
	elif(n > ^k)
		for i(1, 9)
			for(1, a[i])
				do cui@print("\{i}")
			end for
		end for
		do cui@print("\n")
		ret
	end if
	
	block
		var ans: []char :: #[n]char
		var j: int :: 0
		for i(9, 1, -1)
			for(1, a[i])
				do ans[j] :: '0'.offset(i)
				do j :+ 1
			end for
		end for
		if(ans <= k)
			do cui@print("-1\n")
			ret
		end if
	end block
	
	var ans: []char :: #[n]char
	var flag: bool :: false
	for i(0, n - 1)
		for j(1, 9)
			if(a[j] <> 0)
				if(flag)
					do a[j] :- 1
					do ans[i] :: '0'.offset(j)
					skip i
				end if
				if('0'.offset(j) = k[i])
					do a[j] :- 1
					do ans[i] :: '0'.offset(j)
					skip i
				elif('0'.offset(j) > k[i])
					do flag :: true
					do a[j] :- 1
					do ans[i] :: '0'.offset(j)
					skip i
				end if
			end if
		end for
		for j(9, 1, -1)
			if(a[j] <> 0)
				do a[j] :- 1
				do ans[i] :: '0'.offset(j)
				skip i
			end if
		end for
	end for
	if(ans <= k)
		do @nextPermutation(ans)
	end if
	
	for i(0, n - 1)
		do cui@print("\{ans[i]}")
	end for
	do cui@print("\n")
end func

func nextPermutation(arr: []char): 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: char :: 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
0