結果

問題 No.375 立方体のN等分 (1)
ユーザー suppy193suppy193
提出日時 2016-07-11 15:55:44
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 968 bytes
コンパイル時間 108 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 18,432 KB
最終ジャッジ日時 2024-04-21 12:50:08
合計ジャッジ時間 9,008 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 101 ms
12,288 KB
testcase_02 AC 292 ms
12,544 KB
testcase_03 AC 104 ms
12,160 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 103 ms
12,288 KB
testcase_08 AC 290 ms
12,672 KB
testcase_09 WA -
testcase_10 AC 105 ms
12,416 KB
testcase_11 AC 101 ms
12,416 KB
testcase_12 AC 102 ms
12,288 KB
testcase_13 AC 104 ms
12,288 KB
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:36: warning: assigned but unused variable - set
Syntax OK

ソースコード

diff #

require 'prime'
p_arr = []
n = gets.strip.to_i
p = n.prime_division
#p p
p.each do |pf|
	pf[1].times do
		p_arr << pf[0]	
	end
end
min = Float::INFINITY
#p p_arr
(1..(p_arr.length - 2)).each do |i|
	p_arr.combination(i).each do |set1|
		#p set1
		p2_arr = p_arr.clone
		set1.each do |n|
			if p2_arr.index(n) != nil
				p2_arr[p2_arr.index(n)] = nil
			end
		end
		#p p2_arr.compact!
		p2_arr.compact!
		(1..(p2_arr.length - 2)).each do |j|
			p2_arr.combination(j).each do |set2|
				#p set2
				next if set2 == [nil]
				p3_arr = p2_arr.clone
				set2.each do |m|
					if p3_arr.index(m) != nil
						p3_arr[p3_arr.index(m)] = nil
					end
				end
				set3 = p3_arr.compact!
				next if set3 == [nil]
				set = [set1, set2, set3]
				#p set
				num = set1.inject(:*) - 1 + set2.inject(:*) - 1 + set3.inject(:*) - 1
				if num < min
					min = num
				end
			end
		end

	end
end
if min == Float::INFINITY
	print "#{n - 1}"
else
	print "#{min}"
end
print " #{n - 1}\n"
0