結果

問題 No.1594 Three Classes
ユーザー 👑 horiesinitihoriesiniti
提出日時 2023-02-07 04:03:45
言語 Ruby
(3.3.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 11,260 KB
実行使用メモリ 15,652 KB
最終ジャッジ日時 2023-09-18 12:43:08
合計ジャッジ時間 2,947 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,532 KB
testcase_01 AC 77 ms
15,128 KB
testcase_02 AC 77 ms
15,132 KB
testcase_03 AC 82 ms
15,368 KB
testcase_04 AC 82 ms
15,132 KB
testcase_05 AC 83 ms
15,536 KB
testcase_06 AC 80 ms
15,064 KB
testcase_07 AC 82 ms
15,364 KB
testcase_08 AC 84 ms
15,524 KB
testcase_09 AC 83 ms
15,420 KB
testcase_10 AC 82 ms
15,408 KB
testcase_11 AC 83 ms
15,580 KB
testcase_12 AC 83 ms
15,412 KB
testcase_13 AC 77 ms
15,132 KB
testcase_14 AC 83 ms
15,420 KB
testcase_15 AC 83 ms
15,652 KB
testcase_16 AC 81 ms
15,124 KB
testcase_17 AC 82 ms
15,512 KB
testcase_18 AC 77 ms
15,068 KB
testcase_19 AC 79 ms
15,244 KB
testcase_20 AC 79 ms
15,244 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def f(hs,l,r,xs)
	l.upto(r){|i|
		e=xs[i]
		as=hs.keys.to_a
		hs2={}
		as.each{|es|
			hs2[[es[0]+e,es[1],es[2]]]=0
			hs2[[es[0],es[1]+e,es[2]]]=0
			hs2[[es[0],es[1],es[2]+e]]=0
		}
		hs=hs2.dup
	}
	return hs
end

n=gets.to_i
xs=gets.split(" ").map{|e| e.to_i}
s1=xs.sum
if s1%3!=0 then
	puts "No"
else
	s1=s1/3
	hsl={}
	hsr={}
	m=n/2
	hsl[[0,0,0]]=0
	hsr[[0,0,0]]=0
	as=f(hsl,0,m,xs)
	bs=f(hsr,m+1,n-1,xs)
	ans="No"
	as.each{|es1,v|
		ans="Yes" if bs.member?(es1.map{|e| s1-e})
	}
	puts ans
end
0