結果

問題 No.3281 Pacific White-sided Dolphin vs Monster
ユーザー tnakao0123
提出日時 2025-09-28 11:22:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,654 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 60,872 KB
実行使用メモリ 8,900 KB
最終ジャッジ日時 2025-09-28 11:22:09
合計ジャッジ時間 4,997 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:50:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   50 |   scanf("%d", &n);
      |   ~~~~~^~~~~~~~~~
main.cpp:51:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   51 |   for (int i = 0; i < n; i++) scanf("%lld", hs + i);
      |                               ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 3281.cc:  No.3281 Pacific White-sided Dolphin vs Monster - yukicoder
 */

#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int BN = 60;
const int D = 4;
const int DBN = (BN + D - 1) / D;
const int DBITS = 1 << DBN;
const int DMSK = DBITS - 1;
const long long LINF = 1LL << 62;

/* typedef */

using ll = long long;
using vl = vector<ll>;

/* global variables */

int bnums[DBITS];
ll hs[MAX_N];

/* subroutines */

int bitnum(ll n) {
  int b = 0;
  for (int i = 0; i < D; i++, n >>= DBN) b += bnums[n & DMSK];
  return b;
}

/* main */

int main() {
  bnums[0] = 0;
  for (int bits = 1, msb = 1; bits < DBITS; bits++) {
    if ((msb << 1) <= bits) msb <<= 1;
    bnums[bits] = bnums[bits ^ msb] + 1;
  }
  
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%lld", hs + i);

  vl hv(hs, hs + n);
  int cnt = 0;

  for (int i = 0; ! hv.empty() && i < BN; i++) {
    cnt++;
      
    ll bi = 1LL << i;
    vl hv0, hv1;
    
    for (auto h: hv) {
      if ((h & bi) != 0) hv1.push_back(h);
      else hv0.push_back(h);
    }

    if (! hv1.empty()) {
      int minb = BN + 1;
      ll minh = LINF;
      for (auto h: hv1) {
	int b = bitnum(h);
	if (minb > b || (minb == b && minh > h)) minb = b, minh = h;
      }

      for (auto h: hv1) {
	if (h == minh) {
	  if (h > bi) hv0.push_back(h - bi);
	  minh = -1;
	}
	else
	  hv0.push_back(h + bi);
      }

      swap(hv, hv0);

      //printf(" i=%d:", i);
      //for (auto h: hv) printf(" %lld", h); putchar('\n');
    }
  }

  printf("%d\n", cnt + (int)hv.size());
  
  return 0;
}
0