結果
問題 |
No.2025 Select $k$-th Submultiset
|
ユーザー |
![]() |
提出日時 | 2022-07-29 22:45:52 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 1,881 bytes |
コンパイル時間 | 2,067 ms |
コンパイル使用メモリ | 196,772 KB |
最終ジャッジ日時 | 2025-01-30 15:34:50 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 42 |
ソースコード
#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"; } }