結果
問題 |
No.3281 Pacific White-sided Dolphin vs Monster
|
ユーザー |
![]() |
提出日時 | 2025-09-28 11:56:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 992 bytes |
コンパイル時間 | 780 ms |
コンパイル使用メモリ | 63,356 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-09-28 11:56:54 |
合計ジャッジ時間 | 3,443 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:45:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 45 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:46:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | for (int i = 0; i < n; i++) scanf("%lld", hs + i); | ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*- * * 3281.cc: No.3281 Pacific White-sided Dolphin vs Monster - yukicoder */ #include<cstdio> #include<queue> #include<algorithm> using namespace std; /* constant */ const int MAX_N = 100000; const int BN = 60; /* typedef */ using ll = long long; /* global variables */ ll hs[MAX_N]; /* subroutines */ bool check(int n, int x) { if (x > BN) n -= (x - BN), x = BN; if (n <= 0) return true; priority_queue<ll> q(hs, hs + n); for (int i = x - 1; ! q.empty() && i >= 0; i--) { ll bi = 1LL << i; auto h = q.top(); q.pop(); if (h > bi) q.push(h - bi); } return q.empty(); } /* main */ int main() { int n; scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%lld", hs + i); sort(hs, hs + n); int x0 = 0, x1 = n + BN; while (x0 + 1 < x1) { int x = (x0 + x1) / 2; bool f = check(n, x); //printf(" check(%d,%d)=%d\n", n, x, f); if (f) x1 = x; else x0 = x; } printf("%d\n", x1); return 0; }