結果

問題 No.3024 等式
ユーザー cielciel
提出日時 2022-04-02 23:48:12
言語 Ruby
(3.3.0)
結果
AC  
実行時間 4,689 ms / 5,000 ms
コード長 561 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 11,584 KB
実行使用メモリ 15,576 KB
最終ジャッジ日時 2023-09-12 16:18:27
合計ジャッジ時間 8,666 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,188 KB
testcase_01 AC 85 ms
15,312 KB
testcase_02 AC 87 ms
15,316 KB
testcase_03 AC 91 ms
15,152 KB
testcase_04 AC 84 ms
15,156 KB
testcase_05 AC 84 ms
15,376 KB
testcase_06 AC 92 ms
15,560 KB
testcase_07 AC 94 ms
15,352 KB
testcase_08 AC 97 ms
15,460 KB
testcase_09 AC 86 ms
15,320 KB
testcase_10 AC 88 ms
15,364 KB
testcase_11 AC 91 ms
15,456 KB
testcase_12 AC 327 ms
15,196 KB
testcase_13 AC 335 ms
15,436 KB
testcase_14 AC 416 ms
15,416 KB
testcase_15 AC 92 ms
15,508 KB
testcase_16 AC 87 ms
15,312 KB
testcase_17 AC 105 ms
15,576 KB
testcase_18 AC 87 ms
15,360 KB
testcase_19 AC 93 ms
15,380 KB
testcase_20 AC 93 ms
15,296 KB
testcase_21 AC 88 ms
15,208 KB
testcase_22 AC 4,689 ms
15,308 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.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