結果

問題 No.4 おもりと天秤
ユーザー shossiissohsshossiissohs
提出日時 2018-01-10 17:00:55
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,409 ms / 5,000 ms
コード長 555 bytes
コンパイル時間 1,172 ms
コンパイル使用メモリ 144,112 KB
実行使用メモリ 69,124 KB
最終ジャッジ日時 2023-09-08 17:39:48
合計ジャッジ時間 33,736 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 14 ms
5,204 KB
testcase_03 AC 6 ms
4,692 KB
testcase_04 AC 17 ms
7,016 KB
testcase_05 AC 3,263 ms
39,020 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3,320 ms
39,484 KB
testcase_08 AC 2,447 ms
4,380 KB
testcase_09 AC 3,038 ms
69,124 KB
testcase_10 AC 3,409 ms
45,556 KB
testcase_11 AC 4 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
5,496 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3,165 ms
20,080 KB
testcase_19 AC 3,184 ms
34,192 KB
testcase_20 AC 3,186 ms
34,332 KB
testcase_21 AC 3,189 ms
31,396 KB
testcase_22 AC 3,191 ms
32,520 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

bool dp[10001][10001];

int n;
int main() {
  cin >> n;

  dp[0][0] = true;

  int sum = 0;
  for(int i = 0; i < n; i++) {
    int w;
    cin >> w;
    sum += w;
    for(int j = i * 100; j >= 0; j--) {
      for(int k = i * 100; k >= 0; k--) {
	if(dp[j][k]) {
	  dp[j+w][k] = dp[j][k+w] = true;
	}
      }
    }
  }
  for(int i = 1; i < 10001; i++) {
    if(dp[i][i] && i + i == sum) {
      // cout << i << endl;
      cout << "possible" << endl;
      return 0;
    }
  }
  cout << "impossible" <<endl;
}
0