結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
![]() |
提出日時 | 2017-07-11 23:18:27 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 615 bytes |
コンパイル時間 | 1,818 ms |
コンパイル使用メモリ | 169,992 KB |
実行使用メモリ | 10,020 KB |
最終ジャッジ日時 | 2024-10-07 15:10:51 |
合計ジャッジ時間 | 17,187 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 11 WA * 2 TLE * 1 -- * 26 |
ソースコード
#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; }