結果

問題 No.332 数列をプレゼントに
ユーザー code-devocode-devo
提出日時 2016-01-08 18:39:20
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 592 bytes
コンパイル時間 406 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 33,904 KB
最終ジャッジ日時 2023-10-19 16:49:50
合計ジャッジ時間 12,458 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
33,904 KB
testcase_01 AC 89 ms
16,124 KB
testcase_02 AC 89 ms
16,124 KB
testcase_03 AC 90 ms
16,124 KB
testcase_04 AC 88 ms
16,124 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 90 ms
16,124 KB
testcase_08 WA -
testcase_09 AC 88 ms
16,124 KB
testcase_10 AC 88 ms
16,124 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 88 ms
16,124 KB
testcase_25 AC 87 ms
16,124 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 88 ms
16,124 KB
testcase_29 AC 88 ms
16,124 KB
testcase_30 WA -
testcase_31 AC 87 ms
16,124 KB
testcase_32 AC 90 ms
16,124 KB
testcase_33 AC 100 ms
16,232 KB
testcase_34 AC 92 ms
16,124 KB
testcase_35 AC 87 ms
16,124 KB
testcase_36 AC 89 ms
16,124 KB
testcase_37 AC 88 ms
16,124 KB
testcase_38 AC 88 ms
16,124 KB
testcase_39 AC 89 ms
16,124 KB
testcase_40 AC 89 ms
16,124 KB
testcase_41 AC 87 ms
16,124 KB
testcase_42 TLE -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, X = gets.split.map(&:to_i)
A = gets.split.map(&:to_i).sort.reverse
L = A.length
S = A.inject(&:+)

# 配列Aのインデックスi以降の数値をいい感じに足して、
# xを作成できるかどうかを確認する。
# aは答えの文字列。
# sは配列Aのインデックスi以降の数値の合計。
def check(a, i, x, s)
  throw :ok, a + "x" * (L-a.length) if x == 0
  return if s < x
  return if i >= L
  check(a + "o", i + 1, x - A[i], s - A[i]) if x - A[i] >= 0
  check(a + "x", i + 1, x, s - A[i])
end

ans = catch(:ok) do
  check("", 0, X, S)
end
puts ans || "No"
0