結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2016-01-13 17:52:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 583 bytes |
コンパイル時間 | 1,330 ms |
コンパイル使用メモリ | 158,296 KB |
実行使用メモリ | 7,780 KB |
最終ジャッジ日時 | 2024-06-26 09:23:04 |
合計ジャッジ時間 | 2,169 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include<bits/stdc++.h> using namespace std; int n,w[110]; int memo[110][10010]; bool solve(int i,int wl,int wr){ if(wl==wr && i==n){ return true; } if(i>n){ return false; } if(memo[i][wl]!=-1){ return memo[i][wl]; } if(solve(i+1,wl+w[i],wr)){ return memo[i][wl]=true; } if(solve(i+1,wl,wr+w[i])){ return memo[i][wl]=true; } return memo[i][wl]=false; } int main(){ cin>>n; for(int i=0;i<n;i++) cin>>w[i]; memset(memo,-1,sizeof(memo)); if(solve(0,0,0)==true){ cout<<"possible"<<endl; }else{ cout<<"impossible"<<endl; } }