結果

問題 No.15 カタログショッピング
ユーザー Ysmr_RyYsmr_Ry
提出日時 2014-12-30 12:39:43
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 596 ms
コンパイル使用メモリ 76,364 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 20:16:59
合計ジャッジ時間 16,834 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3,039 ms
4,380 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<cstdio>
#include<algorithm>
#include<set>
#include<sstream>
#include<string>
#include<vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define itr(it,a) for(auto it=(a).begin();it!=(a).end();++it)

const int MAX_N = 31;

int N, S;
int P[MAX_N];
int S1[1<<16], S2[1<<16];

int main()
{
	scanf( "%d%d", &N, &S );
	rep( i, N )
		scanf( "%d", P+i );

	rep( i, 1<<(N>>1) ) rep( j, N>>1 ) if( i>>j&1 )
		S1[i] += P[j];
	rep( i, 1<<N-(N>>1) ) rep( j, N-(N>>1) ) if( i>>j&1 )
		S2[i] += P[j+(N>>1)];

	std::set<std::string> s;

	rep( i, 1<<(N>>1) ) rep( j, 1<<N-(N>>1) ) if( S1[i]+S2[j] == S )
	{
		std::ostringstream oss;
		std::vector<int> v;

		rep( k, N>>1 ) if( i>>k&1 )
			v.push_back( k+1 );
		rep( k, N-(N>>1) ) if( j>>k&1 )
			v.push_back( k+1+(N>>1) );
		rep( k, v.size() )
			oss << v[k] << (k==v.size()-1?'\n':' ');

		s.insert( oss.str() );
	}

	itr( it, s )
		printf( "%s", it->c_str() );

	return 0;
}
0