結果

問題 No.1630 Sorting Integers (Greater than K)
ユーザー 👑 tatt61880tatt61880
提出日時 2021-07-31 16:28:49
言語 Kuin
(KuinC++ v.2021.9.17)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,552 bytes
コンパイル時間 2,500 ms
コンパイル使用メモリ 155,672 KB
実行使用メモリ 10,896 KB
最終ジャッジ日時 2023-10-14 18:40:50
合計ジャッジ時間 4,169 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 2 ms
4,352 KB
testcase_10 AC 2 ms
4,356 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 31 ms
10,736 KB
testcase_17 AC 30 ms
10,896 KB
testcase_18 AC 32 ms
10,880 KB
testcase_19 AC 32 ms
10,752 KB
testcase_20 AC 23 ms
10,752 KB
testcase_21 AC 23 ms
10,892 KB
testcase_22 AC 13 ms
5,516 KB
testcase_23 AC 10 ms
5,660 KB
testcase_24 AC 23 ms
9,364 KB
testcase_25 AC 21 ms
5,644 KB
testcase_26 AC 28 ms
10,736 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)
			do cui@print("\{i}".repeat(a[i]))
		end for
		do cui@print("\n")
		ret
	end if
	
	var ans: []char :: #[n]char
	var greaterFlag: bool :: false
	for i(0, n - 1)
		for j(1, 9)
			if(a[j] <> 0)
				if(greaterFlag)
					do a[j] :- 1
					do ans[i] :: '0'.offset(j)
					skip i
				elif('0'.offset(j) = k[i])
					do a[j] :- 1
					do ans[i] :: '0'.offset(j)
					skip i
				elif('0'.offset(j) > k[i])
					do greaterFlag :: true
					do a[j] :- 1
					do ans[i] :: '0'.offset(j)
					skip i
				end if
			end if
		end for
		for j(9, 1, -1)
			for jj(0, a[j] - 1)
				do ans[i + jj] :: '0'.offset(j)
			end for
			do i :+ a[j]
		end for
	end for
	if(ans <= k)
		do @permutationNext(ans)
		if(ans <= k)
			do ans :: "-1"
		end if
	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