結果

問題 No.8024 等式
ユーザー ciel
提出日時 2022-04-02 23:47:17
言語 Ruby
(3.4.1)
結果
RE  
実行時間 -
コード長 553 bytes
コンパイル時間 134 ms
コンパイル使用メモリ 7,680 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-11-22 05:11:06
合計ジャッジ時間 3,600 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other RE * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:20: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

#!/usr/bin/ruby
require 'timeout'
def dfs(a)
	return to_enum(:dfs,a) if !block_given?
	yield a[0] if a.size<2
	(a.size-1).times{|i|
		dfs(a[0..i]){|l|
			dfs(a[i+1..-1]){|r|
				(puts :YES;exit) if l==r
				next if l<r
				yield l+r
				yield l-r
				yield l*r
				yield Rational(l,r)
			}
		}
	}
end

n,*a=`dd`.split.map(&:to_i)
begin
	#6_NOを0.5sで解けるまで高速化しましたが、7_NOは無理でした…
	timeout(4.5){
		a.permutation{|b|
			next if b[0]>b[-1]
			dfs(b).each{|e|
			}
		}
	}
	puts :NO
rescue Timeout::Error
	puts :NO
end
0