結果

問題 No.4 おもりと天秤
コンテスト
ユーザー 777yuuki12323
提出日時 2017-06-28 12:54:18
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 1,140 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 603 ms
コンパイル使用メモリ 98,644 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-13 02:43:06
合計ジャッジ時間 1,335 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>


typedef long long ll;
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789

using namespace std;

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int idx;
int top;
int wa = 0;
int w[112];
int dp[112][5123];


int main(){
	
	int i;
	int j;
	int flag = 0;
	
	cin>>N;
	
	fill( dp[0], dp[N], 0 );
	
	for( i = 0; i < N; i++ ){
		scanf("%d", w+i);
		wa += w[i];
	}
	
	sort( w, w+N );
	
	
	dp[0][0] = 1;
	
	if( wa % 2 == 0 ){
		wa /= 2;
		
		for( i = 1; i <= N; i++ ){
			top = wa-w[i-1];
			for( j = 0; j <= top; j++ ){
				if( dp[i-1][j] ){
					dp[i][j] = dp[i-1][j];
					idx = j+w[i];
					dp[i][idx] = 1;
					if( idx == wa ){
						flag = 1;
						i = mod;
						j = mod;
					}
				}
			}
		}
		
	}
	
	
	if( flag ) puts("possible");
	else{	   puts("impossible");}

	
	return 0;
}
0