結果
| 問題 | No.1594 Three Classes |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-10-31 17:34:36 |
| 言語 | Ruby (4.0.2) |
| 結果 |
AC
|
| 実行時間 | 60 ms / 2,000 ms |
| コード長 | 455 bytes |
| 記録 | |
| コンパイル時間 | 595 ms |
| コンパイル使用メモリ | 8,832 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2026-05-11 14:14:23 |
| 合計ジャッジ時間 | 2,286 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
コンパイルメッセージ
Syntax OK
ソースコード
$N = gets.to_i
$e = gets.split(" ").map{|s| s.to_i}
def search(a, b, c, i)
return true if i == $N
v = $e[i]
if a + v <= $target then
return true if search(a+v, b, c, i+1)
end
if b + v <= $target then
return true if search(a, b+v, c, i+1)
end
if c + v <= $target then
return true if search(a, b, c+v, i+1)
end
return false
end
sum = $e.sum
if sum % 3 != 0 then
puts "No"
else
$target = sum / 3
puts search(0, 0, 0, 0) ? "Yes" : "No"
end