結果

問題 No.3221 Count Turns
ユーザー GOTKAKO
提出日時 2025-08-01 22:14:41
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,939 bytes
コンパイル時間 2,169 ms
コンパイル使用メモリ 209,616 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2025-08-01 22:14:47
合計ジャッジ時間 4,909 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

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

random_device rnd;
mt19937 mt(rnd());


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long N,H,T; cin >> N >> H >> T;
    vector<long long> A(N);
    for(auto &a : A) cin >> a;
    auto solve = [&]() -> void {
        vector<long long> B(N),C(N);
        long long add = 0;
        for(int t=0; t<T; t++){
            
            while(*max_element(B.begin(),B.end()) < H){add++; for(int i=0; i<N; i++) B.at(i) += A.at(i);}
            long long maxb = *max_element(B.begin(),B.end());
            if(t == T-1){
                for(auto b : B) cout << b << " ";
                cout << endl;
            }
            for(int i=0; i<N; i++) if(maxb == B.at(i)){C.at(i)++,B.at(i) = 0; break;}
        }
        cout << add << endl;
        for(auto c : C) cout << c << " "; cout << endl;
    };
    //solve();

    vector<long long> need(N);
    vector<pair<long long,int>> A2(N);
    for(int i=0; i<N; i++){
        long long a = A.at(i);
        long long v = (H+a-1)/a;
        need.at(i) = v; 
        A2.at(i) = {need.at(i)*a,-i};
    }
    sort(A2.begin(),A2.end());
    for(auto &[a,p] : A2) p = -p;

    long long low = 0,high = H*T+2;
    vector<long long> C(N),answer;
    while(high-low > 1){
        long long mid = (high+low)/2;
        long long sum = 0;
        vector<bool> Last(N);
        for(int i=0; i<N; i++){
            long long now = mid/need.at(i);
            sum += now,C.at(i) = now;
            if(now*need.at(i) == mid) Last.at(i) = true; 
        }

        if(sum >= T){
            if(sum-N <= T){
                answer = C;
                for(auto [ign,p] : A2){
                    if(sum == T) break;
                    if(Last.at(p)) sum--,answer.at(p)--;
                }
            }    
            high = mid;
        }
        else low = mid;
    }
    for(auto &a : answer) cout << a << " "; cout << "\n";
}
0