結果

問題 No.4 おもりと天秤
ユーザー autumn-eelautumn-eel
提出日時 2016-12-30 22:22:14
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 10 ms / 5,000 ms
コード長 547 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 164,656 KB
実行使用メモリ 6,640 KB
最終ジャッジ日時 2023-09-08 17:16:23
合計ジャッジ時間 2,517 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

bool dp[101][30000];
int d[100];
int main() {
	int n; scanf("%d", &n);
	rep(i, n)scanf("%d", &d[i]);
	dp[0][15000] = 1;
	rep(i, n) {
		rep(j, 30000) {
			if (j + d[i] < 30000)dp[i + 1][j + d[i]] |= dp[i][j];
			if (j - d[i] >= 0)dp[i + 1][j - d[i]] |= dp[i][j];
		}
	}
	puts(dp[n][15000] ? "possible" : "impossible");
}
0