結果
問題 |
No.4 おもりと天秤
|
ユーザー |
|
提出日時 | 2021-02-21 21:49:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 644 bytes |
コンパイル時間 | 2,338 ms |
コンパイル使用メモリ | 195,484 KB |
最終ジャッジ日時 | 2025-01-19 03:14:26 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; bool dp[5001]; int main() { cin.tie(0); ios::sync_with_stdio(false); memset(dp,false,sizeof(dp)); int n,t; vector <int> v; int sum = 0; cin >> n; for(int i=0;i<n;i++) { cin >> t; sum += t; v.push_back(t); } if(sum%2==1) { cout << "impossible" << '\n'; return 0; } dp[0] = true; for(int i=0;i<n;i++) { for(int j=(sum/2);j>=0;j--) { if(dp[j]==false) { continue; } if(j + v[i] <= (sum/2)) { dp[j + v[i]] = true; } } } if(dp[sum/2]) { cout << "possible" << '\n'; } else { cout << "impossible" << '\n'; } return 0; }