結果

問題 No.2025 Select $k$-th Submultiset
ユーザー RubikunRubikun
提出日時 2022-07-29 22:45:52
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 108 ms / 2,000 ms
コード長 1,881 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 203,880 KB
実行使用メモリ 13,196 KB
最終ジャッジ日時 2023-09-26 22:11:47
合計ジャッジ時間 8,794 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
9,516 KB
testcase_01 AC 3 ms
9,776 KB
testcase_02 AC 4 ms
11,788 KB
testcase_03 AC 98 ms
13,128 KB
testcase_04 AC 71 ms
13,196 KB
testcase_05 AC 105 ms
12,604 KB
testcase_06 AC 88 ms
12,256 KB
testcase_07 AC 86 ms
12,788 KB
testcase_08 AC 94 ms
12,840 KB
testcase_09 AC 100 ms
13,036 KB
testcase_10 AC 101 ms
12,784 KB
testcase_11 AC 97 ms
12,572 KB
testcase_12 AC 108 ms
12,884 KB
testcase_13 AC 82 ms
12,728 KB
testcase_14 AC 91 ms
12,836 KB
testcase_15 AC 101 ms
12,352 KB
testcase_16 AC 96 ms
12,500 KB
testcase_17 AC 92 ms
12,904 KB
testcase_18 AC 101 ms
12,772 KB
testcase_19 AC 92 ms
12,216 KB
testcase_20 AC 100 ms
12,776 KB
testcase_21 AC 85 ms
12,764 KB
testcase_22 AC 98 ms
12,792 KB
testcase_23 AC 100 ms
12,768 KB
testcase_24 AC 90 ms
12,676 KB
testcase_25 AC 2 ms
7,484 KB
testcase_26 AC 3 ms
9,508 KB
testcase_27 AC 3 ms
9,664 KB
testcase_28 AC 3 ms
9,512 KB
testcase_29 AC 2 ms
7,584 KB
testcase_30 AC 3 ms
9,524 KB
testcase_31 AC 3 ms
9,580 KB
testcase_32 AC 3 ms
7,536 KB
testcase_33 AC 3 ms
9,520 KB
testcase_34 AC 3 ms
9,536 KB
testcase_35 AC 2 ms
7,776 KB
testcase_36 AC 4 ms
11,696 KB
testcase_37 AC 4 ms
11,624 KB
testcase_38 AC 3 ms
11,564 KB
testcase_39 AC 4 ms
11,612 KB
testcase_40 AC 3 ms
9,580 KB
testcase_41 AC 2 ms
7,460 KB
testcase_42 AC 3 ms
7,516 KB
testcase_43 AC 3 ms
9,544 KB
testcase_44 AC 2 ms
5,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

ll dp[5][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,L;cin>>N>>L;
    vector<int> c(N);
    for(int i=0;i<N;i++) cin>>c[i];
    dp[N][0]=1;
    for(int i=N;i>=1;i--){
        for(int j=0;j<=L;j++){
            dp[i-1][j]+=dp[i][j];
            dp[i-1][j+c[i-1]+1]-=dp[i][j];
        }
        for(int j=1;j<=L;j++) dp[i-1][j]+=dp[i-1][j-1];
    }
    
    for(int t=0;t<=N;t++){
        for(int j=1;j<=L;j++) dp[t][j]+=dp[t][j-1];
    }
    
    int Q;cin>>Q;
    while(Q--){
        ll x;cin>>x;x--;
        if(x>=(dp[0][L]-dp[0][L-1])){
            cout<<-1<<"\n";
            continue;
        }
        vector<int> ans;
        int rem=L;
        for(int t=0;t<N-1;t++){
            int left=0,right=min(c[t],rem)+1;
            while(right-left>1){
                int mid=(left+right)/2;
                ll xx=dp[t+1][rem-mid];
                if(rem-min(c[t],rem)>0) xx-=dp[t+1][rem-min(c[t],rem)-1];
                if(xx>x){
                    left=mid;
                }else{
                    right=mid;
                }
            }
            ans.push_back(left);
            ll xx=dp[t+1][rem-right];
            if(rem-min(c[t],rem)>0) xx-=dp[t+1][rem-min(c[t],rem)-1];
            x-=xx;
            rem-=left;
        }
        ans.push_back(rem);
        
        for(int x:ans) cout<<x<<" ";
        cout<<"\n";
    }
}
0