結果

問題 No.1594 Three Classes
ユーザー horiesiniti
提出日時 2023-02-07 04:03:45
言語 Ruby
(3.4.1)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-07-05 03:30:35
合計ジャッジ時間 2,925 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
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