結果

問題 No.4 おもりと天秤
ユーザー 777yuuki12323777yuuki12323
提出日時 2017-06-28 12:54:18
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,140 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 74,544 KB
実行使用メモリ 5,528 KB
最終ジャッジ日時 2023-09-08 17:32:05
合計ジャッジ時間 1,701 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
5,528 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
5,396 KB
testcase_08 AC 3 ms
5,448 KB
testcase_09 AC 3 ms
5,392 KB
testcase_10 AC 4 ms
5,452 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 3 ms
5,408 KB
testcase_19 AC 3 ms
5,452 KB
testcase_20 AC 3 ms
5,380 KB
testcase_21 AC 4 ms
5,484 KB
testcase_22 AC 4 ms
5,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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