結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
cww
|
| 提出日時 | 2017-05-05 23:13:21 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 947 bytes |
| コンパイル時間 | 1,735 ms |
| コンパイル使用メモリ | 173,404 KB |
| 実行使用メモリ | 7,296 KB |
| 最終ジャッジ日時 | 2024-06-26 10:15:46 |
| 合計ジャッジ時間 | 2,625 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
vector<vector<int>> visited( 100 + 1, vector<int>( 10000 + 1, -1 ) );
vector<int> W;
int N, total;
bool dfs( int i, int sum )
{
if( i == N )
{
return sum == total / 2 && total % 2 == 0 ? 1 : 0;
}
if( visited[ i ][ sum ] >= 0 )
{
return visited[ i ][ sum ];
}
if( dfs( i + 1, sum ) || dfs( i + 1, sum + W[ i ] ) )
{
visited[ i ][ sum ] = 1;
return visited[ i ][ sum ];
}
visited[ i ][ sum ] = 0;
return visited[ i ][ sum ];
}
int main()
{
cin >> N;
W.resize( N );
for( auto &x : W )
{
cin >> x;
}
total = accumulate( ALL( W ), 0 );
cout << ( dfs( 0, 0 ) ? "possible" : "impossible" ) << endl;
return 0;
}
cww