結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 tatt61880tatt61880
提出日時 2021-07-30 21:52:16
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 1,833 bytes
コンパイル時間 2,477 ms
コンパイル使用メモリ 155,228 KB
実行使用メモリ 12,112 KB
最終ジャッジ日時 2023-10-14 18:39:02
合計ジャッジ時間 4,509 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,356 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 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 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 30 ms
11,788 KB
testcase_17 AC 29 ms
11,788 KB
testcase_18 AC 32 ms
12,112 KB
testcase_19 AC 31 ms
11,716 KB
testcase_20 AC 21 ms
11,896 KB
testcase_21 AC 21 ms
11,792 KB
testcase_22 AC 420 ms
5,712 KB
testcase_23 AC 10 ms
5,508 KB
testcase_24 AC 22 ms
10,064 KB
testcase_25 AC 12 ms
5,804 KB
testcase_26 AC 23 ms
11,704 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
	var failFlag: bool :: false
	for i(0, n - 1)
		if(!failFlag)
			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
		end if
		do failFlag :: true
		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 @permutationNext(ans)
	end if
	
	do cui@print("\{ans}\n")
end func

func permutationNext(array: []char): bool
	var left: int :: ^array - 2
	while(left >= 0 & array[left] >= array[left + 1])
		do left :- 1
	end while
	if(left < 0)
		ret false
	end if
	var right: int :: ^array - 1
	while(array[left] >= array[right])
		do right :- 1
	end while
	var tmp: char :: array[left]
	do array[left] :: array[right]
	do array[right] :: tmp
	do left :+ 1
	do right :: ^array - 1
	while(left < right)
		do tmp :: array[left]
		do array[left] :: array[right]
		do array[right] :: tmp
		do left :+ 1
		do right :- 1
	end while
	ret true
end func
0