結果

問題 No.3281 Pacific White-sided Dolphin vs Monster
ユーザー t98slider
提出日時 2025-09-26 22:04:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,149 bytes
コンパイル時間 2,258 ms
コンパイル使用メモリ 201,020 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-09-26 22:05:08
合計ジャッジ時間 6,127 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 TLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    for(auto &&v : a) cin >> v;
    sort(a.begin(), a.end());
    ll p = 1;
    int ans = 0, cnt = 0;
    constexpr ll th = 1'000'000'000'000'000'000ll;
    while(p <= th && cnt < n){
        bool flg = false;
        for(int i = 0; i < n; i++){
            if(a[i] == 0) continue;
            if(a[i] <= p){
                p = min(2 * p, th);
                ans++;
                cnt++;
                a[i] = 0;
                flg = true;
                break;
            }
        }
        if(flg) continue;
        int pos = 0, mn = -61;
        for(int i = 0; i < n; i++){
            if(a[i] == 0) continue;
            int bcnt = __builtin_popcountll(a[i]) - __builtin_popcountll(a[i] - p);
            if(bcnt > mn){
                mn = bcnt;
                pos = i;
            }
        }
        a[pos] -= p;
        ans++;
        p = min(2 * p, th);
    }
    for(int i = 0; i < n; i++){
        if(a[i] >= 1) ans++;
    }
    cout << ans << '\n';
}
0