結果

問題 No.2142 Segment Zero
ユーザー simansiman
提出日時 2022-12-05 15:08:49
言語 Ruby
(3.3.0)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 300 bytes
コンパイル時間 53 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-04-20 16:18:29
合計ジャッジ時間 7,143 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 89 ms
12,288 KB
testcase_01 AC 159 ms
12,160 KB
testcase_02 AC 89 ms
12,288 KB
testcase_03 AC 88 ms
12,160 KB
testcase_04 AC 229 ms
12,160 KB
testcase_05 AC 230 ms
12,160 KB
testcase_06 AC 87 ms
12,288 KB
testcase_07 AC 111 ms
12,160 KB
testcase_08 AC 217 ms
12,288 KB
testcase_09 AC 138 ms
12,160 KB
testcase_10 AC 217 ms
12,288 KB
testcase_11 AC 223 ms
12,160 KB
testcase_12 AC 218 ms
12,160 KB
testcase_13 AC 219 ms
12,288 KB
testcase_14 AC 218 ms
12,288 KB
testcase_15 AC 216 ms
12,288 KB
testcase_16 AC 217 ms
12,160 KB
testcase_17 AC 199 ms
12,160 KB
testcase_18 AC 90 ms
12,160 KB
testcase_19 AC 104 ms
12,288 KB
testcase_20 AC 161 ms
12,032 KB
testcase_21 AC 142 ms
12,032 KB
testcase_22 AC 181 ms
12,160 KB
testcase_23 AC 102 ms
12,160 KB
testcase_24 AC 113 ms
12,288 KB
testcase_25 AC 103 ms
12,288 KB
testcase_26 AC 129 ms
12,160 KB
testcase_27 AC 115 ms
12,288 KB
testcase_28 AC 147 ms
12,160 KB
testcase_29 AC 160 ms
12,160 KB
testcase_30 AC 189 ms
12,160 KB
testcase_31 AC 90 ms
12,160 KB
testcase_32 AC 115 ms
12,160 KB
testcase_33 AC 96 ms
12,288 KB
testcase_34 AC 109 ms
12,160 KB
testcase_35 AC 214 ms
12,160 KB
testcase_36 AC 115 ms
12,160 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
S = N * (1 + N) / 2

if S == K
  puts 0
  exit
end

sum = N * (1 + N) / 2 - 1
l = 1
r = 1

while l <= r
  if sum == K
    puts 1
    exit
  end

  if r == N
    sum += l
    l += 1
  elsif sum < K
    sum += l
    l += 1
  else
    r += 1
    sum -= r
  end
end

puts 2
0