結果

問題 No.2025 Select $k$-th Submultiset
ユーザー 👑 Nachia
提出日時 2022-07-29 22:01:36
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 138 ms / 2,000 ms
コード長 1,836 bytes
コンパイル時間 4,051 ms
コンパイル使用メモリ 138,976 KB
最終ジャッジ日時 2025-01-30 15:15:38
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <atcoder/modint>
#include <atcoder/segtree>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<998244353>;


namespace RQ{
    u64 op(u64 l, u64 r){ return l+r; }
    u64 e(){ return 0; }
    using RQ = atcoder::segtree<u64,op,e>;
}


int main(){
    int N; cin >> N;
    int L; cin >> L;
    vector<int> C(N); rep(i,N) cin >> C[i];
    reverse(C.begin(), C.end());
    vector<vector<u64>> dp(N+1, vector<u64>(L+1,0));
    dp[0][0] = 1;
    rep(d,N){
        RQ::RQ rq(dp[d]);
        rep(i,L+1) dp[d+1][i] = rq.prod(max(0,i-C[d]), i+1);
    }

    vector<vector<u64>> sumDp(N+1, vector<u64>(L+2,0));
    rep(d,N+1) rep(i,L+1) sumDp[d][i+1] = sumDp[d][i] + dp[d][i];

    rep(i,N+1){
        //rep(j,L+2) cout << sumDp[i][j] << " ";
        //cout << endl;
    }

    int Q; cin >> Q;
    rep(qi, Q){
        u64 k; cin >> k;
        if(dp[N][L] < k){ cout << "-1\n"; continue; }
        vector<int> res(N);
        int len = L;
        for(int d=N-1; d>=0; d--){
            //cout << "k = " << k << " , len = " << len << endl;
            u64 off = sumDp[d][max(0,len-C[d])];
            int c = (lower_bound(sumDp[d].begin(), sumDp[d].end(), k+off) - sumDp[d].begin()) - 1;
            k = k - sumDp[d][c] + off;
            c = len - c;
            res[N-1-d] = c;
            len -= c;
        }
        rep(i,N){ if(i){ cout << ' '; } cout << res[i]; } cout << '\n';
    }
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0