結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  cww | 
| 提出日時 | 2017-04-17 00:09:20 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 6 ms / 5,000 ms | 
| コード長 | 1,006 bytes | 
| コンパイル時間 | 1,721 ms | 
| コンパイル使用メモリ | 172,048 KB | 
| 実行使用メモリ | 7,168 KB | 
| 最終ジャッジ日時 | 2024-06-26 10:14:06 | 
| 合計ジャッジ時間 | 2,359 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| 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>> dp( 100 + 1, vector<int>( 10000 + 1 ) );
vector<int> w;
int N, total;
void solved()
{
    for( int i = N - 1; i >= 0; i-- )
    {
        for( int j = 0; j <= total; j++ )
        {
            // 対象外
            if( j < w[ i ] )
            {
                dp[ i ][ j ] = dp[ i + 1 ][ j ];
                continue;
            }
            // 加えない場合と加える場合を両方試す
            dp[ i ][ j ] = max( dp[ i + 1 ][ j ], dp[ i + 1 ][ j - w[ i ] ] + w[ i ] );
        }
    }
    cout << ( dp[ 0 ][ total / 2 ] == total / 2 && total % 2 == 0 ? "possible" : "impossible" ) << endl;
}
int main()
{
	cin >> N;
	w.resize( N );
	for( auto &x : w )
	{
		cin >> x;
	}
	total = accumulate( ALL( w ), 0 );
	solved();
    return 0;
}
            
            
            
        