結果

問題 No.4 おもりと天秤
ユーザー soupesuteakasoupesuteaka
提出日時 2014-12-29 01:16:18
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 950 bytes
コンパイル時間 602 ms
コンパイル使用メモリ 84,092 KB
実行使用メモリ 7,528 KB
最終ジャッジ日時 2023-09-03 19:25:51
合計ジャッジ時間 3,876 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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[i-1]>=0) dp[i][j] |= dp[i-W[i-1]][j-1];
		}
		if (dp[s][N]) cout << "possible\n";
		else cout << "impossible\n";
	}
	
	return 0;
}
0