結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2017-03-26 19:27:14 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 856 bytes |
コンパイル時間 | 571 ms |
コンパイル使用メモリ | 66,364 KB |
実行使用メモリ | 7,420 KB |
最終ジャッジ日時 | 2024-06-26 10:12:17 |
合計ジャッジ時間 | 1,399 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <queue> #include <vector> #include <cmath> #include <cctype> #define rep(i,a,b) for(int i=(a);i<b;i++) #define INF 1000000000 using namespace std; bool debug=false; int sum=0; int dp[101][10001]; int n,w[100]; void solve(){ dp[0][0]=true; for(int i=0;i<n;i++){ for(int j=0;j<10001;j++){ if(dp[i][j]){ dp[i+1][j+w[i]]=true; dp[i+1][j]=true; } } } if(debug){ for(int i=0;i<10;i++){ for(int j=0;j<10;j++){ cout<<" "<<dp[i][j]; } cout<<endl; } } if(dp[n-1][sum/2])cout<<"possible"<<endl; else cout<<"impossible"<<endl; } int main(){ cin>>n; rep(i,0,n){ cin>>w[i]; sum+=w[i]; } if(sum%2==1){ cout<<"impossible"<<endl; return 0; } rep(i,0,n)rep(j,0,10001)dp[i][j]=false; solve(); return 0; }