結果

問題 No.294 SuperFizzBuzz
ユーザー te-shte-sh
提出日時 2017-06-09 11:54:28
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 2,512 bytes
コンパイル時間 1,503 ms
コンパイル使用メモリ 140,712 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-03 14:05:15
合計ジャッジ時間 2,528 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;
import std.format;

const comt = [0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 2, 2, 1, 2, 1, 1, 1, 3, 3, 3, 2, 3, 2, 2, 3, 6, 5, 5, 5, 5, 5, 5, 6, 11, 10, 10, 11, 10, 11, 11, 11, 21, 21, 21, 22, 21, 22, 22, 21, 42, 43, 43, 43, 43, 43, 43, 42, 85, 86, 86, 85, 86, 85, 85, 85, 171, 171, 171, 170, 171, 170, 170, 171, 342, 341, 341, 341, 341, 341, 341, 342, 683, 682, 682, 683, 682, 683, 683, 683, 1365, 1365, 1365, 1366, 1365, 1366, 1366, 1365, 2730, 2731, 2731, 2731, 2731, 2731, 2731, 2730, 5461, 5462, 5462, 5461, 5462, 5461, 5461, 5461, 10923, 10923, 10923, 10922, 10923, 10922, 10922, 10923, 21846, 21845, 21845, 21845, 21845, 21845, 21845, 21846, 43691, 43690, 43690, 43691, 43690, 43691, 43691, 43691, 87381, 87381, 87381, 87382, 87381, 87382, 87382, 87381, 174762, 174763, 174763, 174763, 174763, 174763, 174763, 174762, 349525, 349526, 349526, 349525, 349526, 349525, 349525, 349525, 699051, 699051, 699051, 699050, 699051, 699050, 699050, 699051];

const coms = comt.cumulativeFold!"a + b".array;

const bt = [0, 1, 1, 2, 1, 2, 2, 3];

void main()
{
  auto n = readln.chomp.to!int;

  if (n == 1) {
    writeln(555);
    return;
  }

  --n;

  auto a = coms.assumeSorted.lowerBound(n), al = a.length.to!int;
  auto b = al / 8, c = al % 8, m = n - a.back - 1;

  auto ct = 0;
  foreach (i; 0..(1 << b)) {
    if ((i.popcnt + bt[c] + 1) % 3 == 0) {
      if (ct++ == m) {
        writeln(toOutput(b, c, i));
        return;
      }
    }
  }
  writeln(ct);
}

auto toOutput(int b, int c, int i)
{
  auto t = b > 0 ? format("%0" ~ b.to!string ~ "b", i) : "";
  auto s = format("%03b", c) ~ t ~ '1';
  return s.tr(['0', '1'], ['3', '5']);
}

pragma(inline) {
  pure bool bitTest(T)(T n, size_t i) { return (n & (T(1) << i)) != 0; }
  pure T bitSet(T)(T n, size_t i) { return n | (T(1) << i); }
  pure T bitReset(T)(T n, size_t i) { return n & ~(T(1) << i); }
  pure T bitComp(T)(T n, size_t i) { return n ^ (T(1) << i); }

  pure T bitSet(T)(T n, size_t s, size_t e) { return n | ((T(1) << e) - 1) & ~((T(1) << s) - 1); }
  pure T bitReset(T)(T n, size_t s, size_t e) { return n & (~((T(1) << e) - 1) | ((T(1) << s) - 1)); }
  pure T bitComp(T)(T n, size_t s, size_t e) { return n ^ ((T(1) << e) - 1) & ~((T(1) << s) - 1); }

  import core.bitop;
  pure int bsf(T)(T n) { return core.bitop.bsf(ulong(n)); }
  pure int bsr(T)(T n) { return core.bitop.bsr(ulong(n)); }
  pure int popcnt(T)(T n) { return core.bitop.popcnt(ulong(n)); }
}
0