結果

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

ソースコード

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;
        pair<ll,ll> mn = {61, 61};
        for(int i = 0; i < n; i++){
            if(a[i] == 0) continue;
            pair<ll,ll> pa = make_pair(__builtin_popcountll(a[i] - p) - (int)__builtin_popcountll(a[i]), 
                                        __builtin_popcountll(a[i] - p));
            if(pa < mn){
                mn = pa;
                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