結果

問題 No.2025 Select $k$-th Submultiset
ユーザー 沙耶花沙耶花
提出日時 2022-07-29 22:45:43
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,281 bytes
コンパイル時間 4,675 ms
コンパイル使用メモリ 262,288 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-26 22:12:54
合計ジャッジ時間 41,116 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1,869 ms
4,384 KB
testcase_04 AC 1,440 ms
4,380 KB
testcase_05 AC 1,811 ms
4,380 KB
testcase_06 AC 1,709 ms
4,380 KB
testcase_07 TLE -
testcase_08 AC 1,966 ms
4,384 KB
testcase_09 AC 1,790 ms
4,384 KB
testcase_10 AC 1,877 ms
4,384 KB
testcase_11 AC 1,836 ms
4,384 KB
testcase_12 AC 1,950 ms
4,384 KB
testcase_13 AC 1,845 ms
4,380 KB
testcase_14 TLE -
testcase_15 AC 1,868 ms
4,380 KB
testcase_16 AC 1,935 ms
4,384 KB
testcase_17 TLE -
testcase_18 AC 1,848 ms
4,384 KB
testcase_19 AC 1,810 ms
4,384 KB
testcase_20 AC 1,665 ms
4,504 KB
testcase_21 AC 1,807 ms
4,380 KB
testcase_22 TLE -
testcase_23 AC 1,924 ms
4,384 KB
testcase_24 AC 1,943 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,388 KB
testcase_33 AC 2 ms
4,504 KB
testcase_34 AC 2 ms
4,384 KB
testcase_35 AC 1 ms
4,384 KB
testcase_36 AC 3 ms
4,384 KB
testcase_37 AC 1 ms
4,384 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 2 ms
4,388 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 1 ms
4,388 KB
testcase_42 AC 1 ms
4,384 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001

int N,L;
long long k;

long long get(long long n){
	//cout<<'a'<<','<<n<<endl;
	long long ret = 1;
	rep(i,N-1){
		ret *= n-i;
	}
	rep(i,N-1){
		ret /=i+1;
	}
	return ret;
	
}

long long get(vector<long long> l,vector<long long> r){
	
	long long ret = 0;
	rep(i,1<<N){
		long long LL = L;
		int t = 0;
		rep(j,N){
			if((i>>j)&1){
				LL -= l[j];
				
			}
			else{
				t++;
				LL -= r[j]+1;
			}
		}
		if(LL<0)continue;
		long long c = get(LL+N-1);

		if(t%2==1)c*=-1;
		ret += c;
	}
	return ret;
}

int main() {
    
	
	cin>>N>>L;
	vector<long long> c(N);
	rep(i,N)cin>>c[i];
	
	int Q;
	cin>>Q;
	
	rep(_,Q){
		
		cin>>k;
		vector<long long> l(N,0),r=c;
		//cout<<get(l,r)<<endl;
		if(get(l,r)<k){
			cout<<-1<<endl;
			continue;
		}
		vector<long long> ans;
		rep(i,N){
			long long ok = 0,ng = r[i]+1;
			while(ng-ok>1LL){
				long long mid = (ok+ng)/2;
				l[i] = mid;
				if(get(l,r)>=k)ok = mid;
				else ng = mid;
			}
			l[i] = ok+1;
			k -= get(l,r);
			l[i] = ok;
			r[i] = ok;
			
		}
		rep(i,N){
			if(i!=0)cout<<' ';
			cout<<l[i];
		}
		cout<<endl;
	}
	
	
    return 0;
}
0