結果

問題 No.4 おもりと天秤
ユーザー MicrobeMicrobe
提出日時 2017-08-03 19:00:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 967 bytes
コンパイル時間 1,471 ms
コンパイル使用メモリ 163,692 KB
実行使用メモリ 4,696 KB
最終ジャッジ日時 2023-09-08 17:33:26
合計ジャッジ時間 2,479 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

bool dp[101][10001];

int main() {
	int N, W[100];
	int sum = 0;
	scanf("%d", &N);
	memset(dp, false, sizeof(dp));
	rep(i, N) {
		scanf("%d", &W[i]);
		sum += W[i];
	}
	dp[0][0] = true;
	rep(i, N) {
		rep(j, 10001) {
			if (dp[i][j]) {
				dp[i + 1][j + W[i]] = true;
				dp[i + 1][j] = true;
			}
		}
	}
	(dp[N][sum / 2] && sum % 2 == 0) ? printf("possible\n") : printf("impossible\n");
	return 0;
}
0