結果

問題 No.4 おもりと天秤
ユーザー syake_tasyake_ta
提出日時 2018-08-26 17:49:50
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,508 bytes
コンパイル時間 573 ms
コンパイル使用メモリ 84,256 KB
実行使用メモリ 4,620 KB
最終ジャッジ日時 2023-09-13 19:20:34
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,436 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 5 ms
4,492 KB
testcase_03 AC 4 ms
4,376 KB
testcase_04 AC 5 ms
4,428 KB
testcase_05 RE -
testcase_06 AC 3 ms
4,380 KB
testcase_07 RE -
testcase_08 AC 3 ms
4,608 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 WA -
testcase_12 AC 3 ms
4,620 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 3 ms
4,408 KB
testcase_15 AC 3 ms
4,376 KB
testcase_16 AC 4 ms
4,384 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:66:15: warning: iteration 10001 invokes undefined behavior [-Waggressive-loop-optimizations]
    if (dp[i][j] == true) {
        ~~~~~~~^
main.cpp:65:21: note: within this loop
   for (int j = 0; j <= 100000; j++) {
                   ~~^~~~~~~~~

ソースコード

diff #

#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>
#include<utility>
#include<numeric>

#define PB push_back
#define all(a)  (a).begin(),(a).end()
#define ALL(v) begin(v), end(v)
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define V vector<int>
#define VV vector<V>
#define VVV vector<VV>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int inf = (int)1e9;
const ll INF = (ll)1e18;
const ll MOD{ (ll)1e9 + 7 };
const long double EPS = 1e-10;

bool dp[101][10001];

int main() {
	int n, w[101];
	cin >> n;
	rep(i, n) cin >> w[i];

	rep(i, 101) {
		rep(j, 10001) {
			dp[i][j] = false;
		}
	}

	int sum = 0;
	rep(i, n) sum += w[i];

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

	dp[0][0] = true;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= 100000; j++) {
			if (dp[i][j] == true) {
				dp[i + 1][j + w[i]] = true; //左の天秤
				dp[i + 1][j] = true;        //右の天秤
			}
		}
	}

	if (dp[n][sum / 2] == true) {  //釣り合うとき、左 = sum / 2
		cout << "possible" << endl;
	}
	else {
		cout << "impossible" << endl;
	}
	
	return 0;
}
0