結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-05 22:44:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 776 bytes |
| コンパイル時間 | 494 ms |
| コンパイル使用メモリ | 55,256 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 23:34:53 |
| 合計ジャッジ時間 | 1,262 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <string.h>
using namespace std;
int main(){
int n;
cin >> n;
int weight[n];
int sum_weight = 0;
for (int i = 0; i < n; i++){
cin >> weight[i];
sum_weight += weight[i];
}
if (sum_weight % 2 == 1){
cout << "impossible" << endl;
return 0;
}
int half_weight = sum_weight / 2;
// 重さjを作れるか
int dp[half_weight + 1];
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 0; i < n; i++){
int w = weight[i];
for (int j = half_weight; j >= w; j--){
dp[j] |= dp[j - w];
}
}
if (dp[half_weight] == 1){
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
return 0;
}