結果

問題 No.942 プレゼント配り
ユーザー simansiman
提出日時 2022-02-17 02:14:40
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 867 bytes
コンパイル時間 63 ms
コンパイル使用メモリ 11,360 KB
実行使用メモリ 23,764 KB
最終ジャッジ日時 2023-09-11 17:22:26
合計ジャッジ時間 4,844 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
15,116 KB
testcase_01 AC 173 ms
18,480 KB
testcase_02 AC 80 ms
15,172 KB
testcase_03 AC 79 ms
15,256 KB
testcase_04 AC 220 ms
22,184 KB
testcase_05 AC 170 ms
18,612 KB
testcase_06 AC 81 ms
15,100 KB
testcase_07 AC 80 ms
15,112 KB
testcase_08 AC 187 ms
20,532 KB
testcase_09 AC 202 ms
22,084 KB
testcase_10 AC 82 ms
15,116 KB
testcase_11 AC 83 ms
15,256 KB
testcase_12 AC 81 ms
15,028 KB
testcase_13 AC 81 ms
15,120 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 81 ms
15,320 KB
testcase_19 AC 80 ms
15,260 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:57: warning: assigned but unused variable - nums
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)

if K == 1
  puts 'Yes'
  puts [*1..N].join(' ')
  exit
end

if N % K != 0
  puts 'No'
  exit
end

S = N * (1 + N) / 2
M = N / K

if S % K != 0
  puts 'No'
  exit
end

if N % 2 == 0 && M % 2 != 0
  puts 'No'
  exit
end

if M == 1
  puts 'No'
  exit
end

1.upto(N) do |n|
end

presents = [*1..N].each_slice(K).to_a
puts 'Yes'
ans = Array.new(K) { [] }
from = 0

if M % 2 != 0
  presents[2].reverse_each.with_index do |n, i|
    ans[i] << n
  end

  K.times do |i|
    ans[i] << (2 * i) % K + 1
  end

  K.times do |i|
    ans[i] << 24 - ans[i].sum
  end

  from = 3
end

from.upto(M - 1) do |idx|
  nums = presents[idx]

  if idx % 2 == 0
    0.upto(K - 1) do |k|
      ans[k] << presents[idx].shift
    end
  else
    0.upto(K - 1) do |k|
      ans[k] << presents[idx].pop
    end
  end
end

ans.each do |nums|
  puts nums.join(' ')
end
0