結果

問題 No.4 おもりと天秤
ユーザー nksk38nksk38
提出日時 2017-10-11 20:36:27
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,185 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 80,144 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 16:12:19
合計ジャッジ時間 2,942 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;
typedef pair<string, string> pss;

int n,sum;
int w[110];
int dp[110][110];

int main()
{
	cin >> n;

	rep(i, n) {
		cin >> w[i+1];
		sum += w[i+1];
	}

	if (sum % 2 != 0) {
		cout << "impossible" << endl;
		return 0;
	}

	dp[0][0] = 0;

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sum/2; j++) {
			if (j < w[i]) {
				dp[i][j] = dp[i - 1][j];
			}else{
				dp[i][j] = max(dp[i - 1][j-w[i-1]]+w[i],
					dp[i-1][j]);
			}
		}
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j <= sum/2; j++) {
			if (dp[i][j] == sum / 2) {
				cout << "possible" << endl;
				return 0;
			}
		}
	}
	cout << "impossible" << endl;
	return 0;
}
0