結果

問題 No.14 最小公倍数ソート
ユーザー warashiwarashi
提出日時 2015-11-21 11:46:04
言語 Go
(1.21.3)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 10,637 ms
コンパイル使用メモリ 202,964 KB
実行使用メモリ 5,880 KB
最終ジャッジ日時 2023-08-01 03:51:29
合計ジャッジ時間 12,431 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 11 ms
4,376 KB
testcase_04 AC 88 ms
5,880 KB
testcase_05 AC 51 ms
4,376 KB
testcase_06 AC 58 ms
5,800 KB
testcase_07 AC 63 ms
5,824 KB
testcase_08 AC 73 ms
5,852 KB
testcase_09 AC 84 ms
5,872 KB
testcase_10 AC 84 ms
5,872 KB
testcase_11 AC 85 ms
5,872 KB
testcase_12 AC 86 ms
5,872 KB
testcase_13 AC 85 ms
5,876 KB
testcase_14 AC 84 ms
5,872 KB
testcase_15 AC 85 ms
5,872 KB
testcase_16 AC 55 ms
5,844 KB
testcase_17 AC 45 ms
4,380 KB
testcase_18 AC 30 ms
4,376 KB
testcase_19 AC 69 ms
5,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"sort"
)

func divisors(num int) []int {
	var ret []int
	for i := 1; i*i <= num; i++ {
		if num%i == 0 {
			ret = append(ret, i)
			if i*i != num {
				ret = append(ret, num/i)
			}
		}
	}
	sort.Ints(ret)
	return ret
}

var dp, m [10001]int

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
		m[A[i]]++
	}

	next := A[0]
	m[next]--
	fmt.Print(next)

	for i := 0; i < N-1; i++ {
		divisor := divisors(next)
		check := 99999
		ans := 0

		for _, d := range divisor {
			for d*dp[d] <= 10000 {
				if m[d*dp[d]] > 0 {
					if check <= dp[d] {
						break
					}
					ans = d * dp[d]
					check = dp[d]
				} else {
					dp[d]++
				}
			}
		}

		next = ans
		m[next]--
		fmt.Print(" ", next)
	}
	fmt.Print("\n")
}
0