結果

問題 No.1456 Range Xor
ユーザー kanno_kannokanno_kanno
提出日時 2021-04-22 19:36:48
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 570 bytes
コンパイル時間 180 ms
コンパイル使用メモリ 11,564 KB
実行使用メモリ 23,208 KB
最終ジャッジ日時 2023-09-17 10:16:13
合計ジャッジ時間 7,936 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,084 KB
testcase_01 AC 81 ms
15,044 KB
testcase_02 AC 80 ms
15,048 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 87 ms
16,216 KB
testcase_12 AC 84 ms
15,528 KB
testcase_13 AC 95 ms
17,564 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 99 ms
18,464 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 87 ms
15,764 KB
testcase_25 AC 95 ms
17,000 KB
testcase_26 AC 100 ms
18,908 KB
testcase_27 WA -
testcase_28 AC 91 ms
16,576 KB
testcase_29 AC 113 ms
22,020 KB
testcase_30 WA -
testcase_31 AC 89 ms
16,648 KB
testcase_32 AC 87 ms
16,276 KB
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 112 ms
21,700 KB
testcase_38 AC 88 ms
16,020 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 81 ms
15,068 KB
testcase_42 AC 86 ms
15,552 KB
testcase_43 AC 80 ms
15,088 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 AC 79 ms
15,076 KB
testcase_47 AC 80 ms
15,076 KB
testcase_48 AC 81 ms
15,300 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def reverse_calc(i, k, nums)
  tmp = nums[i]
  (0...i).to_a.reverse.each do |j|
    break if (tmp + nums[j]) > k

    tmp += nums[j]
  end

  tmp
end

def solve(line1, line2)
  n, k = line1.split.map(&:to_i)
  nums = line2.split.map(&:to_i)

  tmp = 0
  (0...n).each do |i|
    return 'No' if nums[i] > k
    next if (i != 0) && (nums[i - 1] == nums[i])

    tmp += nums[i]
    return 'Yes' if tmp == k

    # Kを超えた場合は再計算
    tmp = reverse_calc(i, k, nums) if tmp > k
  end

  'No'
end

line1 = gets.chomp
line2 = gets.chomp
puts solve(line1, line2)
0