結果

問題 No.237 作図可能性
ユーザー not_522not_522
提出日時 2015-08-04 10:56:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,327 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 145,028 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-25 01:00:02
合計ジャッジ時間 2,801 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

template<typename T> int least_bit(T n) {
  if (sizeof(T) == 4) return __builtin_ffs(n) - 1;
  if (sizeof(T) == 8) return __builtin_ffsll(n) - 1;
  assert(false);
}

template<typename T> int most_bit(T n) {
  if (sizeof(T) == 4) return n ? 31 - __builtin_clz(n) : -1;
  if (sizeof(T) == 8) return n ? 63 - __builtin_clzll(n) : -1;
  assert(false);
}

template<typename T> int count_bit(T n) {
  if (sizeof(T) == 4) return __builtin_popcount(n);
  if (sizeof(T) == 8) return __builtin_popcountll(n);
  assert(false);
}

class BitIterator {
public:

  class Iterator {
  private:
    int val, bit;

  public:
    Iterator(int val, int bit) : val(val), bit(bit) {}

    Iterator operator*() {
      return *this;
    }

    bool operator!=(const Iterator& itr) const {
      return val != itr.val;
    }

    void operator++() {
      val = least_bit(bit & (-1 << (val + 1)));
    }

    operator int() {
      return val;
    }
  };
  
  Iterator i, n;
  int bit;

  BitIterator(int n) : i(least_bit(n), n), n(-1, n), bit(n) {}

  bool operator!=(const BitIterator& itr) const {
    return i != itr.i;
  }

  void operator++() {
    *this = BitIterator(bit + 1);
  }

  operator int() const {
    return bit;
  }

  bool in(int i) const {
    return bit & (1 << i);
  }

  Iterator& begin() {
    return i;
  }

  Iterator& end() {
    return n;
  }
};

class PowerSet {
private:
  class Iterator {
  private:
    BitIterator val;

  public:
    Iterator(int val) : val(val) {}

    Iterator operator*() {
      return *this;
    }

    bool operator!=(Iterator& itr) {
      return val != itr.val;
    }

    void operator++() {
      ++val;
    }

    operator int() const {
      return val;
    }

    bool in(int i) const {
      return val.in(i);
    }

    BitIterator::Iterator& begin() {
      return val.begin();
    }

    BitIterator::Iterator& end() {
      return val.end();
    }
  };

  Iterator i, n;

public:
  PowerSet(int n) : i(0), n(1 << n) {}

  Iterator& begin() {
    return i;
  }

  Iterator& end() {
    return n;
  }
};

int main() {
  int a;
  cin >> a;
  int f[] = {3, 5, 17, 257, 65537};
  int res = -2;
  for (auto i : PowerSet(5)) {
    long long k = 1;
    for (auto j : i) k *= f[j];
    res += most_bit(a / k) + 1;
  }
  cout << res << endl;
}
0