結果

問題 No.14 最小公倍数ソート
ユーザー warashiwarashi
提出日時 2015-11-21 11:46:04
言語 Go
(1.22.1)
結果
AC  
実行時間 82 ms / 5,000 ms
コード長 797 bytes
コンパイル時間 11,670 ms
コンパイル使用メモリ 222,768 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-19 03:35:00
合計ジャッジ時間 13,217 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 1 ms
5,248 KB
testcase_03 AC 10 ms
5,376 KB
testcase_04 AC 82 ms
5,376 KB
testcase_05 AC 46 ms
5,376 KB
testcase_06 AC 52 ms
5,376 KB
testcase_07 AC 59 ms
5,376 KB
testcase_08 AC 67 ms
5,376 KB
testcase_09 AC 78 ms
5,376 KB
testcase_10 AC 75 ms
5,376 KB
testcase_11 AC 80 ms
5,376 KB
testcase_12 AC 79 ms
5,376 KB
testcase_13 AC 82 ms
5,376 KB
testcase_14 AC 80 ms
5,376 KB
testcase_15 AC 81 ms
5,376 KB
testcase_16 AC 50 ms
5,376 KB
testcase_17 AC 43 ms
5,376 KB
testcase_18 AC 30 ms
5,376 KB
testcase_19 AC 65 ms
5,376 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