結果

問題 No.942 プレゼント配り
ユーザー simansiman
提出日時 2022-02-17 02:20:13
言語 Ruby
(3.3.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 919 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 23,804 KB
最終ジャッジ日時 2023-09-11 17:22:46
合計ジャッジ時間 4,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,116 KB
testcase_01 AC 172 ms
18,624 KB
testcase_02 AC 79 ms
15,272 KB
testcase_03 AC 80 ms
15,248 KB
testcase_04 AC 219 ms
22,312 KB
testcase_05 AC 169 ms
18,652 KB
testcase_06 AC 79 ms
15,300 KB
testcase_07 AC 80 ms
15,128 KB
testcase_08 AC 184 ms
20,660 KB
testcase_09 AC 199 ms
22,184 KB
testcase_10 AC 80 ms
15,036 KB
testcase_11 AC 81 ms
15,244 KB
testcase_12 AC 80 ms
15,220 KB
testcase_13 AC 79 ms
15,036 KB
testcase_14 AC 216 ms
23,804 KB
testcase_15 AC 157 ms
20,048 KB
testcase_16 AC 172 ms
19,424 KB
testcase_17 AC 174 ms
20,580 KB
testcase_18 AC 78 ms
15,268 KB
testcase_19 AC 79 ms
15,140 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:59: 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

  mid = (0..2).map { |x| presents[x][K / 2] }.sum

  K.times do |i|
    ans[i] << mid - 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