結果

問題 No.1701 half price
ユーザー harurunharurun
提出日時 2021-02-22 01:57:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 1,039 ms
コンパイル使用メモリ 104,636 KB
実行使用メモリ 5,000 KB
最終ジャッジ日時 2023-09-30 09:22:23
合計ジャッジ時間 2,914 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,504 KB
testcase_01 AC 2 ms
4,500 KB
testcase_02 AC 42 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 42 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 411 ms
4,380 KB
testcase_07 AC 413 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
5,000 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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