結果

問題 No.2025 Select $k$-th Submultiset
ユーザー 👑 NachiaNachia
提出日時 2022-07-29 22:01:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 1,836 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 89,688 KB
実行使用メモリ 11,552 KB
最終ジャッジ日時 2023-09-26 20:55:42
合計ジャッジ時間 9,459 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 5 ms
4,380 KB
testcase_03 AC 98 ms
11,520 KB
testcase_04 AC 90 ms
11,528 KB
testcase_05 AC 107 ms
10,676 KB
testcase_06 AC 90 ms
9,216 KB
testcase_07 AC 105 ms
11,496 KB
testcase_08 AC 102 ms
10,624 KB
testcase_09 AC 107 ms
11,356 KB
testcase_10 AC 111 ms
11,064 KB
testcase_11 AC 106 ms
10,468 KB
testcase_12 AC 111 ms
11,552 KB
testcase_13 AC 92 ms
10,932 KB
testcase_14 AC 100 ms
11,028 KB
testcase_15 AC 105 ms
10,940 KB
testcase_16 AC 105 ms
10,988 KB
testcase_17 AC 106 ms
10,996 KB
testcase_18 AC 102 ms
10,024 KB
testcase_19 AC 96 ms
9,452 KB
testcase_20 AC 101 ms
9,584 KB
testcase_21 AC 98 ms
10,036 KB
testcase_22 AC 105 ms
10,164 KB
testcase_23 AC 104 ms
10,620 KB
testcase_24 AC 98 ms
10,200 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,384 KB
testcase_27 AC 1 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,384 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 1 ms
4,380 KB
testcase_36 AC 2 ms
4,384 KB
testcase_37 AC 2 ms
4,380 KB
testcase_38 AC 2 ms
4,380 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

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