結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2023-04-30 20:12:13 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 5 ms / 5,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 1,788 ms |
コンパイル使用メモリ | 175,056 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-19 09:57:02 |
合計ジャッジ時間 | 2,740 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define srep(i, s, n) for (int i=(s); i < (int)(n); i++) #define all(v) v.begin(), v.end() #define fore(i,x) for(auto i:x) #define pb push_back using vi=vector<int>; using vvi=vector<vi>; using vb=vector<bool>; using vvb=vector<vb>; using vs=vector<string>; using vll=vector<long long>; using vvll=vector<vll>; using vc=vector<char>; using vvc=vector<vc>; using ll=long long; void Yes(bool ok){ cout << (ok ? "Yes" : "No") << "\n";} int main(){ int N; cin >> N; vi W(N); rep(i,N) cin >> W.at(i); int S=0; vvb dp(N+1,vb(10001)); dp.at(0).at(0)=true; rep(i,N) S+=W.at(i); bool ans=false; if(S%2==0){ rep(i,N){ rep(j,10001){ if(dp.at(i).at(j)){ dp.at(i+1).at(j)=true; dp.at(i+1).at(j+W.at(i))=true; } } } rep(i,N+1){ if(dp.at(i).at(S/2)) ans=true; } } if(ans) cout << "possible" << "\n"; else cout << "impossible" << "\n"; }