結果

問題 No.4 おもりと天秤
ユーザー soupesuteakasoupesuteaka
提出日時 2014-12-29 01:20:42
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 5 ms / 5,000 ms
コード長 950 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 83,068 KB
実行使用メモリ 7,540 KB
最終ジャッジ日時 2023-09-08 16:04:49
合計ジャッジ時間 1,697 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
7,452 KB
testcase_01 AC 5 ms
7,308 KB
testcase_02 AC 4 ms
7,388 KB
testcase_03 AC 5 ms
7,424 KB
testcase_04 AC 4 ms
7,352 KB
testcase_05 AC 5 ms
7,304 KB
testcase_06 AC 4 ms
7,288 KB
testcase_07 AC 5 ms
7,508 KB
testcase_08 AC 4 ms
7,428 KB
testcase_09 AC 5 ms
7,308 KB
testcase_10 AC 5 ms
7,368 KB
testcase_11 AC 5 ms
7,380 KB
testcase_12 AC 4 ms
7,304 KB
testcase_13 AC 5 ms
7,304 KB
testcase_14 AC 5 ms
7,292 KB
testcase_15 AC 5 ms
7,364 KB
testcase_16 AC 4 ms
7,540 KB
testcase_17 AC 5 ms
7,364 KB
testcase_18 AC 5 ms
7,292 KB
testcase_19 AC 5 ms
7,296 KB
testcase_20 AC 5 ms
7,364 KB
testcase_21 AC 5 ms
7,304 KB
testcase_22 AC 5 ms
7,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <iomanip>

#define INF 1000000001
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
const double PI = acos(-1.0);

int N;
int W[101];

int dp[10001][101];

int main()
{
	ios::sync_with_stdio(false);

	cin >> N;
	FOR(i,0,N) cin >> W[i];

	memset(dp, 0, sizeof(dp));
	int s=0;
	FOR(i,0,N) s+=W[i];
	if (s%2) {
		cout << "impossible\n";
	} else {
		s/=2;
		FOR(i,0,N+1) dp[0][i] = 1;
		FOR(i,1,s+1) FOR(j,1,N+1) {
			dp[i][j] = dp[i][j-1];
			if (i-W[j-1]>=0) dp[i][j] |= dp[i-W[j-1]][j-1];
		}

		if (dp[s][N]) cout << "possible\n";
		else cout << "impossible\n";
	}

	return 0;
}
0