結果

問題 No.294 SuperFizzBuzz
ユーザー yuruhiyayuruhiya
提出日時 2020-10-24 19:12:53
言語 Crystal
(1.10.0)
結果
MLE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 21,323 ms
コンパイル使用メモリ 262,444 KB
実行使用メモリ 814,220 KB
最終ジャッジ日時 2023-09-13 12:30:14
合計ジャッジ時間 24,618 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,524 KB
testcase_01 AC 3 ms
4,412 KB
testcase_02 MLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます

ソースコード

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 enum_len(len, size)
  strings = Array(Array(Char)).new(size)
  (3..len).step(3) do |cnt5|
    (0...len - 1).to_a.each_combination(len - cnt5) do |ind3|
      string = Array.new(len, '5')
      ind3.each { |i| string[i] = '3' }
      strings << string
    end
  end
  strings
end

def func(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, tmp} if sum + tmp >= n
    sum += tmp
  end
end

n = read_line.to_i64
len, num, val = func(n).not_nil!
puts enum_len(len, val).sort[num - 1].join
0