結果
問題 |
No.3281 Pacific White-sided Dolphin vs Monster
|
ユーザー |
|
提出日時 | 2025-09-27 14:22:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 27 ms / 2,000 ms |
コード長 | 1,182 bytes |
コンパイル時間 | 1,835 ms |
コンパイル使用メモリ | 203,452 KB |
実行使用メモリ | 7,720 KB |
最終ジャッジ日時 | 2025-09-27 14:22:38 |
合計ジャッジ時間 | 4,518 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:40:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=] 40 | printf("%d\n", t); | ~^ ~ | | | | int ll {aka long long int} | %lld main.cpp:14:42: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 14 | for (int i = 1; i < n + 1; i++) scanf("%lld", h + i); | ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; typedef long long ll; const int N = 2000086, MOD = 998244353, INF = 0x3f3f3f3f; int n, m, w[N]; ll h[N]; int main() { cin >> n; for (int i = 1; i < n + 1; i++) scanf("%lld", h + i); sort(h + 1, h + n + 1); set<ll, greater<ll> > l; ll sum = 0, ans = 0; for (ll i = 1; i < (1ll << 62); i <<= 1) l.insert(i), sum += i; for (int i = 1; i < n + 1; i++) { if (sum >= h[i]) { ll t = sum; for (auto u = l.begin(); u != l.end() && h[i] > 0; ) { t -= *u; if (*u <= h[i]) { h[i] -= *u; sum -= *u; u = l.erase(u); } else if (t < h[i]) { h[i] -= *u; sum -= *u; u = l.erase(u); } else u++; } } else ans++; } if (ans) printf("%lld\n", ans + 62); else { for (ll i = (1ll << 61), t = 62; i >= 1; i >>= 1, t--) if (!l.count(i)) { printf("%d\n", t); return 0; } } return 0; }