結果
問題 | No.1701 half price |
ユーザー |
![]() |
提出日時 | 2021-02-22 02:29:28 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 509 ms / 3,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 1,328 ms |
コンパイル使用メモリ | 102,812 KB |
最終ジャッジ日時 | 2025-01-19 03:19:08 |
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <iostream> #include <math.h> #include <string> #include <vector> #include <unordered_set> using namespace std; string change(int n,int k){ string ret=""; while(n!=0){ ret+=to_string(n%k); n/=k; } return ret; } int main(){ int N,W,a,cnt=0,n,m,b,x; long long s; string u; cin>>N>>W; vector<int> A; for(int i=0;i<N;i++){ cin>>a; if(a==0)cnt++; else A.push_back(a); } if(W==0){ cout<<pow(2,cnt)-1<<endl; return 0; } n=N-cnt; m=pow(3,n); unordered_set<int> ans; for(int i=0;i<m;i++){ s=0; b=0; x=1; u=change(i,3); for(int j=0;j<(int)u.size();j++){ if(u[j]=='1'){ s+=A[j]; b+=x; } else if(u[j]=='2'){ s+=A[j]/2; b+=x; } x*=2; } if(s==W)ans.insert(b); } cout<<ans.size()*pow(2,cnt)<<endl; return 0; }