結果
| 問題 |
No.8024 等式
|
| コンテスト | |
| ユーザー |
ei1333333
|
| 提出日時 | 2017-04-01 00:35:29 |
| 言語 | Ruby (3.4.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,015 bytes |
| コンパイル時間 | 41 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,544 KB |
| 最終ジャッジ日時 | 2024-07-07 14:26:28 |
| 合計ジャッジ時間 | 3,542 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 23 |
コンパイルメッセージ
Syntax OK
ソースコード
# Here your code !
require "mathn"
OPERATORS=[ "+", "\\-", "*", "/", "_" ]
EXPRESSIONS=%w[
AxByCzD ((AxB)yC)zD (AxB)y(CzD)
(Ax(ByC))zD Ax((ByC)zD) Ax(By(CzD))
]
def solve( *nums0 )
nums0.permutation(nums0.size) do |nums|
OPERATORS.repeated_permutation(nums0.length-1).each do |ops|
EXPRESSIONS.each do |exp|
begin
yield eval(exp.tr( "ABCDxyz", (nums+ops).join ))
rescue SyntaxError, ZeroDivisionError
end
end
end
end
end
n = gets.to_i
a = gets.split.map{|m|m.to_i}
S = 1 << n
flag = false
S.times do |bit|
x = []
y = []
c = 0
d = 0
n.times do |s|
if (bit >> s).to_i % 2 == 0
x.push(a[s])
c += 1
else
y.push(a[s])
d += 1;
end
end
if c > 0 and d > 0
if !(enum_for(:solve, x).to_a - enum_for(:solve, y).to_a).empty? and !flag
puts("YES")
flag = true
end
end
end
if !flag
puts("NO")
end
ei1333333