結果
問題 | No.4 おもりと天秤 |
ユーザー |
![]() |
提出日時 | 2016-11-14 12:47:42 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 791 bytes |
コンパイル時間 | 1,717 ms |
コンパイル使用メモリ | 171,076 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-26 10:04:23 |
合計ジャッジ時間 | 2,550 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, j) for(int i=0; i < (int)(j); i++) #define all(v) v.begin(),v.end() template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; } int main() { int N; cin >> N; vector<int> W(N); cin >> W; int sum = accumulate(all(W), 0); if(sum % 2 == 0) { vector<bool> ok(sum / 2 + 1); ok[0] = true; rep(i, N) { for(int j = ok.size() -1; j >= 0; j--) { if(ok[j] and j + W[i] < ok.size()) { ok[j + W[i]] = true; } } } if(ok.back()) { cout << "possible" << endl; return 0; } } cout << "impossible" << endl; return 0; }