結果

問題 No.2449 square_permutation
ユーザー simansiman
提出日時 2023-09-01 15:09:41
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 434 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 24,300 KB
最終ジャッジ日時 2023-09-01 15:09:52
合計ジャッジ時間 9,014 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
15,260 KB
testcase_01 AC 77 ms
15,092 KB
testcase_02 AC 78 ms
15,296 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 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 AC 78 ms
15,096 KB
testcase_23 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N = gets.to_i

ans = [*0..N]
checked = Hash.new(false)

1.upto(N) do |i|
  n = 1
  max_v = 0

  while (n + 1) ** 2 * i <= N
    n += 1

    max_v = n * n * i if !checked[n * n * i]
  end

  if Math.sqrt(i).to_i ** 2 == i
    while (n + 1) ** 2 < N
      n += 1

      max_v = n * n if !checked[n * n]
    end
  end

  checked[max_v] = true
  if max_v > i
    ans[i], ans[max_v] = ans[max_v], ans[i]
  end
end

puts ans[1..].join(' ')
0