結果

問題 No.4 おもりと天秤
ユーザー KoshStormKoshStorm
提出日時 2017-12-16 20:41:56
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 695 bytes
コンパイル時間 1,387 ms
コンパイル使用メモリ 149,996 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-21 11:14:24
合計ジャッジ時間 2,329 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
using namespace std;

int main(void){
	short N;
	cin >> N;
	vector<short> W(N);

	long sum = 0;

	REP(i,N){
		cin >> W[i];
		sum += W[i];
	}

	if (sum % 2) {
		cout << "impossible\n";
		exit(0);
	}

	#ifdef DEBUG
		cout << "sum ==> " << sum << "\n";
	#endif


	vector<vector<char>>dp(N+1, vector<char>(sum/2+1, 0));
	REP(i,N) dp[i][0] = 1;

	REP(i,N){
		REP(j,sum/2+1){
			if ((j - W[j]) >= 0){
				dp[i+1][j] = MAX(dp[i][j-W[i+1]],dp[i][j]);
			}
		}	
	}

	if (dp[N][sum/2]) cout << "possible\n";
	else cout << "impossible\n";


	return 0;
}
0