結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
hotwater2010
|
| 提出日時 | 2020-08-21 22:36:49 |
| 言語 | Ruby (3.4.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 439 bytes |
| コンパイル時間 | 44 ms |
| コンパイル使用メモリ | 7,296 KB |
| 実行使用メモリ | 24,320 KB |
| 最終ジャッジ日時 | 2024-10-15 06:00:46 |
| 合計ジャッジ時間 | 7,213 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 TLE * 1 -- * 17 |
コンパイルメッセージ
Syntax OK
ソースコード
$n = gets.to_i
$w = gets.split.map(&:to_i)
$nerai = $w.inject(:+)/2.0
$flag = "impossible"
def dfs(depth, total)
if depth >= $n - 1
return total + $w[depth] if total + $w[depth] == $nerai
return total if total == $nerai
return -1
end
a = dfs(depth+1, total+$w[depth])
b = dfs(depth+1, total)
return a if $nerai - a == 0
return b if $nerai - b == 0
return -1
end
puts dfs(-1, 0) > 0 ? "possible" : "impossible"
hotwater2010