結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2014-10-19 18:16:13 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 745 bytes |
コンパイル時間 | 563 ms |
コンパイル使用メモリ | 59,868 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 09:01:49 |
合計ジャッジ時間 | 1,388 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#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; w[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; }