結果

問題 No.4 おもりと天秤
ユーザー zazaboonzazaboon
提出日時 2017-02-04 19:37:52
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 514 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,460 KB
実行使用メモリ 15,356 KB
最終ジャッジ日時 2023-08-25 20:13:59
合計ジャッジ時間 3,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
15,240 KB
testcase_01 AC 81 ms
15,144 KB
testcase_02 AC 82 ms
15,080 KB
testcase_03 WA -
testcase_04 AC 82 ms
15,132 KB
testcase_05 AC 98 ms
15,156 KB
testcase_06 AC 81 ms
15,128 KB
testcase_07 AC 99 ms
15,072 KB
testcase_08 AC 79 ms
15,196 KB
testcase_09 WA -
testcase_10 AC 98 ms
15,100 KB
testcase_11 AC 80 ms
15,044 KB
testcase_12 AC 81 ms
15,256 KB
testcase_13 AC 80 ms
15,184 KB
testcase_14 AC 80 ms
15,280 KB
testcase_15 AC 79 ms
15,084 KB
testcase_16 AC 78 ms
15,096 KB
testcase_17 WA -
testcase_18 AC 99 ms
15,336 KB
testcase_19 AC 101 ms
15,244 KB
testcase_20 AC 96 ms
15,232 KB
testcase_21 AC 94 ms
15,128 KB
testcase_22 AC 96 ms
15,176 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)
$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