結果

問題 No.4 おもりと天秤
ユーザー zazaboonzazaboon
提出日時 2017-02-04 19:44:31
言語 Ruby
(3.3.0)
結果
RE  
実行時間 -
コード長 518 bytes
コンパイル時間 54 ms
コンパイル使用メモリ 11,308 KB
実行使用メモリ 15,464 KB
最終ジャッジ日時 2023-08-25 20:14:03
合計ジャッジ時間 3,142 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
15,260 KB
testcase_01 AC 80 ms
15,060 KB
testcase_02 AC 79 ms
15,324 KB
testcase_03 AC 79 ms
15,304 KB
testcase_04 AC 78 ms
15,108 KB
testcase_05 AC 89 ms
15,364 KB
testcase_06 RE -
testcase_07 AC 91 ms
15,272 KB
testcase_08 AC 78 ms
15,244 KB
testcase_09 AC 79 ms
15,172 KB
testcase_10 AC 90 ms
15,016 KB
testcase_11 AC 79 ms
15,156 KB
testcase_12 RE -
testcase_13 AC 77 ms
15,088 KB
testcase_14 AC 78 ms
15,292 KB
testcase_15 AC 78 ms
15,100 KB
testcase_16 AC 77 ms
15,064 KB
testcase_17 AC 76 ms
15,160 KB
testcase_18 AC 100 ms
15,232 KB
testcase_19 AC 86 ms
15,364 KB
testcase_20 AC 86 ms
15,160 KB
testcase_21 AC 87 ms
15,056 KB
testcase_22 AC 88 ms
15,156 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:28: warning: `:' after local variable or literal is interpreted as binary operator
Main.rb:28: warning: even though it seems like symbol literal
Syntax OK

ソースコード

diff #

def zent(x,s)
    return if($f == 1)
    return if(s > $s)
    return if(x >= $n)
    if(s == $s)
        $f = 1; return;
    end
    return if($memo[s] < x)
    zent(x+1,s)
    $memo[s] = x if $memo[s] > x
    s += $a[x]
    zent(x+1,s)
    $memo[s] = x if $memo[s] > x
end
$f = 0
$n=gets.chomp.to_i
$a=gets.chomp.split(" ").map(&:to_i)
$a.sort!
$s = $a.inject(:+)
if ($s%2 == 1)
    puts "impossible"
    exit
end
$s = $s/2
$memo = Array.new($s*2)
$memo.fill(9990)
zent(0,0)
puts ($f == 1)? "possible" :"impossible"
0