結果

問題 No.115 遠足のおやつ
ユーザー dnishdnish
提出日時 2017-07-11 23:18:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 615 bytes
コンパイル時間 1,598 ms
コンパイル使用メモリ 165,640 KB
実行使用メモリ 8,576 KB
最終ジャッジ日時 2024-04-16 17:06:13
合計ジャッジ時間 17,896 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 2,224 ms
5,376 KB
testcase_08 AC 6 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 4,443 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 37 ms
5,376 KB
testcase_15 WA -
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int) N;i++)
#define RREP(i,n,N) for(int i=N-1;i>=(int) n;i--)
using namespace std;

int main() {
	int N,D,K;
	cin>>N>>D>>K;
	vector<int> ans;
	RREP(mask,1,(1<<N)){
		int sum=0;
		if(__builtin_popcount(mask)==K){
			REP(i,0,N){
				if(mask & (1<<i)) sum+=i+1;
			}
			if(sum==D){
				REP(i,0,N){
					if(mask & (1<<i)) ans.push_back(i+1);
				}
				break;
			}
		}
	}
	if(ans.empty()) cout<<-1<<endl;
	else{
		bool flag=false;
		for(auto p:ans){
			if(!flag) {
				cout<<p;
				flag=true;
			}else{
				cout<<" "<<p;
			}
		}
		cout<<endl;
	}
	return 0;
}
0