結果

問題 No.24 数当てゲーム
ユーザー koturnkoturn
提出日時 2016-02-09 00:07:41
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 973 bytes
コンパイル時間 454 ms
コンパイル使用メモリ 57,084 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 20:26:48
合計ジャッジ時間 1,057 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdlib>
#include <array>
#include <iostream>

#ifdef __GNUC__
#  define popcnt(n)  __builtin_popcount(n)
#else
static unsigned int
popcnt(unsigned int n)
{
  unsigned int cnt = 0;
  while (n != 0) {
    cnt += (n & 0x01);
    n >>= 1;
  }
}
#endif


std::size_t
bsf(unsigned int n)
{
  for (std::size_t i = 0, len = sizeof(n) * 3; i < len; i++, n >>= 1) {
    if ((n & 0x01) == 0x01) {
      return i;
    }
  }
  return -1;
}


static const int MASK = 0x03ff;


int
main()
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int n;
  std::cin >> n;
  int candidateBit = MASK;
  for (int i = 0; popcnt(candidateBit) != 1 && i < n; i++) {
    std::array<int, 4> ns;
    std::string result;
    std::cin >> ns[0] >> ns[1] >> ns[2] >> ns[3] >> result;
    int n = ((1 << ns[0]) | (1 << ns[1]) | (1 << ns[2]) | (1 << ns[3]));
    candidateBit &= result == "YES" ? n : (~n & MASK);
  }
  std::cout << bsf(candidateBit) << std::endl;

  return EXIT_SUCCESS;
}
0