結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2016-01-13 17:51:22 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 583 bytes |
コンパイル時間 | 1,260 ms |
コンパイル使用メモリ | 158,524 KB |
実行使用メモリ | 7,404 KB |
最終ジャッジ日時 | 2024-09-19 18:56:30 |
合計ジャッジ時間 | 3,078 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 RE * 9 |
ソースコード
#include<bits/stdc++.h> using namespace std; int n,w[100]; int memo[100][10001]; 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; } }