結果

問題 No.1701 half price
ユーザー harurun
提出日時 2021-02-22 01:57:04
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 1,034 ms
コンパイル使用メモリ 103,520 KB
最終ジャッジ日時 2025-01-19 03:18:36
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 19 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#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,s,b,x;
	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<n;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;
}
0