結果
問題 | No.4 おもりと天秤 |
ユーザー |
|
提出日時 | 2017-09-15 16:33:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 4 ms / 5,000 ms |
コード長 | 681 bytes |
コンパイル時間 | 806 ms |
コンパイル使用メモリ | 90,300 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 10:22:40 |
合計ジャッジ時間 | 1,627 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <stack> #include <queue> #include <set> #include <vector> #include <string> #include <string.h> #include <iomanip> #include <limits> using namespace std; const int MAX_N=10000; int n; bool dp[10001]; //dp[i]:=重さがiになるような組み合わせが存在するか。 int main(){ cin >> n; fill(dp,dp+sizeof(dp)/sizeof(dp[0]),false); dp[0]=true; int w,s=0; for(int i=0;i<n;i++){ cin >> w; s+=w; for(int j=10001;j>=w;j--) if(dp[j-w]) dp[j]=true; } if(s%2==0){ if(dp[s/2]){ cout << "possible" << endl; return 0; } } cout << "impossible" << endl; return 0; }