結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-06-28 15:06:56 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 778 bytes |
| コンパイル時間 | 498 ms |
| コンパイル使用メモリ | 65,792 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-30 23:25:52 |
| 合計ジャッジ時間 | 1,416 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 8 |
ソースコード
#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[sum_weight + 1];
memset(dp, 0, sizeof(dp));
dp[0] = 1;
for (int i = 0; i < n; i++){
int w = weight[i];
for (int j = 0; j <= sum_weight - w; j++){
dp[j + w] |= dp[j];
}
}
if (dp[sum_weight] == 1){
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
return 0;
}