結果

問題 No.294 SuperFizzBuzz
ユーザー yuruhiyayuruhiya
提出日時 2020-10-24 22:30:10
言語 Crystal
(1.11.2)
結果
AC  
実行時間 64 ms / 5,000 ms
コード長 867 bytes
コンパイル時間 21,973 ms
コンパイル使用メモリ 264,260 KB
実行使用メモリ 4,540 KB
最終ジャッジ日時 2023-09-13 12:31:15
合計ジャッジ時間 23,036 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,540 KB
testcase_01 AC 3 ms
4,380 KB
testcase_02 AC 64 ms
4,420 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,428 KB
testcase_05 AC 3 ms
4,540 KB
testcase_06 AC 3 ms
4,516 KB
testcase_07 AC 2 ms
4,492 KB
testcase_08 AC 6 ms
4,520 KB
testcase_09 AC 41 ms
4,380 KB
testcase_10 AC 3 ms
4,468 KB
testcase_11 AC 53 ms
4,472 KB
testcase_12 AC 58 ms
4,444 KB
testcase_13 AC 61 ms
4,516 KB
testcase_14 AC 64 ms
4,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

lib C
  fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64
end

class String
  def to_i64
    C.strtoll(self, nil, 10)
  end
end

def enumrate_combination(n)
  res = Array.new(n + 1) { Array.new(n + 1, 0i64) }
  (0..n).each do |i|
    res[i][0] = res[i][i] = 1
  end
  (1..n).each do |i|
    (1...i).each do |j|
      res[i][j] = res[i - 1][j - 1] + res[i - 1][j]
    end
  end
  res
end

Comb = enumrate_combination(26)

def calc_len(n)
  sum = 0i64
  (3..100).each do |len|
    tmp = (3..len).step(3).sum do |cnt5|
      Comb[len - 1][cnt5 - 1]
    end
    return {len, n - sum} if sum + tmp >= n
    sum += tmp
  end
end

n = read_line.to_i64
len, num = calc_len(n).not_nil!
STDERR.puts([len, num])

(0...2**len).each do |i|
  num -= 1 if i.popcount % 3 == 0 && i.bit(0) == 1
  if num == 0
    puts i.to_s(2).rjust(len, '0').tr("01", "35")
    exit
  end
end
0