結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2014-10-19 18:15:08 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 742 bytes |
| コンパイル時間 | 1,363 ms |
| コンパイル使用メモリ | 60,152 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 09:46:51 |
| 合計ジャッジ時間 | 1,565 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 3 |
ソースコード
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
int main(){
int n;
std::cin >> n;
int *w = (int*)malloc(sizeof(int)* n);
for(register int i =0; i < n; i++)
std::cin >> w[i];
long sum;
sum = 0;
for(register int i = 0; i < n; i++)
sum += w[i];
bool *dp = (bool*)malloc(sizeof(bool) * (sum + 1));
dp[0] = true;
if(sum % 2) dp[n-1] = false;
else{
for(register long i = 0; i < n; i++){
for(register long j = sum/2; i - 1 < j; j--){
dp[j] |= dp[j-w[i]];
}
}
}
if(dp[sum/2] == true) std::cout << "possible" << std::endl;
else std::cout << "impossible" << std::endl;
}