結果
| 問題 | No.15 カタログショッピング |
| コンテスト | |
| ユーザー |
Ysmr_Ry
|
| 提出日時 | 2014-12-30 12:51:56 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,194 bytes |
| 記録 | |
| コンパイル時間 | 715 ms |
| コンパイル使用メモリ | 79,400 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 01:06:53 |
| 合計ジャッジ時間 | 1,239 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
23 | scanf( "%d%d", &N, &S );
| ~~~~~^~~~~~~~~~~~~~~~~~
main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf( "%d", P+i );
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include<cstdio>
#include<algorithm>
#include<set>
#include<sstream>
#include<string>
#include<utility>
#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)
typedef std::pair<int, int> Pr;
const int MAX_N = 31;
int N, S;
int P[MAX_N];
int S1[1<<16];
Pr 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].first += P[j+(N>>1)];
S2[i].second = i;
}
std::sort( S2, S2+(1<<N-(N>>1)) );
std::set<std::string> s;
Pr *p;
rep( i, 1<<(N>>1) ) if( (p = std::lower_bound( S2, S2+(1<<N-(N>>1)), Pr( S-S1[i], 0 ) ))->first == S-S1[i] )
{
do
{
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( p->second>>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() );
} while( (++p)->first == S-S1[i] );
}
itr( it, s )
printf( "%s", it->c_str() );
return 0;
}
Ysmr_Ry