結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2017-12-17 16:04:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 836 bytes |
コンパイル時間 | 825 ms |
コンパイル使用メモリ | 82,816 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-15 22:27:07 |
合計ジャッジ時間 | 3,075 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 14 RE * 9 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <queue> #include <set> #include <map> using namespace std; #define FOR(i,s,e) for(int i = (s);i <= (e);i++) vector<vector<bool>> dp(100,vector<bool>(5050,false)); int W[101]; int N; int total = 0; int main() { cin >> N; FOR(i,0,N - 1) { cin >> W[i]; total += W[i]; } if(total % 2 == 1) { cout << "impossible" << endl; return 0; } dp[0][0] = true; FOR(i,0,N - 1) { FOR(j,0,5049) { dp[i + 1][j] = dp[i][j] || dp[i + 1][j]; if(dp[i][j]) { dp[i + 1][j + W[i]] = true; } } } if(dp[N][total / 2]) cout << "possible" << endl; else cout << "impossible" << endl; return 0; }