結果

問題 No.2025 Select $k$-th Submultiset
ユーザー 👑 kmjpkmjp
提出日時 2022-07-29 23:21:32
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 1,546 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 201,180 KB
実行使用メモリ 10,776 KB
最終ジャッジ日時 2023-09-26 23:06:11
合計ジャッジ時間 11,358 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
9,880 KB
testcase_01 AC 4 ms
9,744 KB
testcase_02 AC 5 ms
10,740 KB
testcase_03 AC 210 ms
10,604 KB
testcase_04 AC 196 ms
10,636 KB
testcase_05 AC 226 ms
10,572 KB
testcase_06 AC 212 ms
10,572 KB
testcase_07 AC 216 ms
10,536 KB
testcase_08 AC 224 ms
10,540 KB
testcase_09 AC 225 ms
10,492 KB
testcase_10 AC 226 ms
10,508 KB
testcase_11 AC 224 ms
10,576 KB
testcase_12 AC 232 ms
10,580 KB
testcase_13 AC 209 ms
10,652 KB
testcase_14 AC 212 ms
10,544 KB
testcase_15 AC 221 ms
10,492 KB
testcase_16 AC 221 ms
10,492 KB
testcase_17 AC 223 ms
10,544 KB
testcase_18 AC 228 ms
10,580 KB
testcase_19 AC 222 ms
10,492 KB
testcase_20 AC 230 ms
10,492 KB
testcase_21 AC 216 ms
10,536 KB
testcase_22 AC 225 ms
10,776 KB
testcase_23 AC 226 ms
10,744 KB
testcase_24 AC 216 ms
10,584 KB
testcase_25 AC 4 ms
9,640 KB
testcase_26 AC 5 ms
9,840 KB
testcase_27 AC 5 ms
9,792 KB
testcase_28 AC 5 ms
9,716 KB
testcase_29 AC 4 ms
9,472 KB
testcase_30 AC 5 ms
9,740 KB
testcase_31 AC 4 ms
9,776 KB
testcase_32 AC 4 ms
9,680 KB
testcase_33 AC 5 ms
9,804 KB
testcase_34 AC 5 ms
9,848 KB
testcase_35 AC 5 ms
9,532 KB
testcase_36 AC 6 ms
10,664 KB
testcase_37 AC 5 ms
10,512 KB
testcase_38 AC 6 ms
10,532 KB
testcase_39 AC 6 ms
10,496 KB
testcase_40 AC 5 ms
9,780 KB
testcase_41 AC 5 ms
9,484 KB
testcase_42 AC 4 ms
9,488 KB
testcase_43 AC 5 ms
9,712 KB
testcase_44 AC 4 ms
9,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,L;
int C[4];

ll dp[5][102010];
ll S[5][102010];


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>L;
	FOR(i,N) cin>>C[i];
	
	dp[N][0]=1;
	FOR(i,101010) S[N][i]=1;
	for(j=N-1;j>=0;j--) {
		FOR(i,101010) {
			dp[j][i]=S[j+1][i];
			if(i>C[j]) dp[j][i]-=S[j+1][i-C[j]-1];
			
			S[j][i]=dp[j][i];
			if(i) S[j][i]+=S[j][i-1];
		}
	}
	
	int Q;
	cin>>Q;
	while(Q--) {
		ll K;
		cin>>K;
		
		if(dp[0][L]<K) {
			cout<<-1<<endl;
			continue;
		}
		
		int cur=L;
		int R[4]={};
		FOR(i,N) {
			int ma=min(cur,C[i]);
			for(j=20;j>=0;j--) if(ma>=(1<<j)) {
				ll su=S[i+1][cur-(ma-(1<<j))-1]-S[i+1][cur-ma-1];
				if(su<K) {
					K-=su;
					ma-=1<<j;
				}
			}
			
			R[i]=ma;
			cur-=ma;
			cout<<R[i]<<" ";
		}
		cout<<endl;
		
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0