結果

問題 No.1953 8
ユーザー tomeruntomerun
提出日時 2022-05-20 23:43:02
言語 Crystal
(1.11.2)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 17,035 ms
コンパイル使用メモリ 280,392 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-10-20 14:39:53
合計ジャッジ時間 21,770 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,372 KB
testcase_02 AC 2 ms
4,372 KB
testcase_03 AC 2 ms
4,372 KB
testcase_04 AC 2 ms
4,372 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,372 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 1 ms
4,372 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 2 ms
4,372 KB
testcase_12 AC 1 ms
4,372 KB
testcase_13 AC 2 ms
4,372 KB
testcase_14 AC 2 ms
4,372 KB
testcase_15 AC 1 ms
4,372 KB
testcase_16 AC 2 ms
4,372 KB
testcase_17 AC 1 ms
4,372 KB
testcase_18 AC 2 ms
4,372 KB
testcase_19 AC 2 ms
4,372 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 2 ms
4,372 KB
testcase_22 AC 2 ms
4,372 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 2 ms
4,372 KB
testcase_25 AC 2 ms
4,372 KB
testcase_26 AC 1 ms
4,372 KB
testcase_27 AC 2 ms
4,372 KB
testcase_28 AC 2 ms
4,372 KB
testcase_29 AC 2 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

C  = [1i64, 0i64, 0i64, 0i64, 1i64, 0i64, 1i64, 0i64, 2i64, 1i64]
CS = [0i64]
C.size.times do |i|
  CS << CS[i] + C[i]
end
CNT = [0i64, CS[-1]]
1.upto(16) do |i|
  CNT << CNT[i] + (CS[-1] - 1) * (10i64 ** i) + CS[-1] * 9 * (10i64 ** (i - 1)) * i
end
k = read_line.to_i64 + 1
lo = 0i64
hi = 100000000000000000i64
while hi - lo > 1
  mid = (lo + hi) // 2
  # puts [mid, cnt(mid, mid.to_s.size - 1, 1)]
  if cnt(mid, mid.to_s.size - 1, 1) > k
    hi = mid
  else
    lo = mid
  end
end
puts cnt(lo, lo.to_s.size - 1, 1) == k ? lo : -1

def cnt(v, len, first)
  if len == 0
    return CS[v + 1]
  end
  hi = v // (10i64 ** len)
  rest = v - hi * (10i64 ** len)
  ret = 0i64
  if first == 1
    ret += CNT[len]
  end
  ret += (CS[hi] - first) * (10i64 ** len)
  ret += (hi - first) * CS[-1] * (10i64 ** (len - 1)) * len
  ret += C[hi] * (rest + 1)
  ret += cnt(rest, len - 1, 0)
  # puts [v, len, ret]
  return ret
end
0