結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
kakeyamay
|
| 提出日時 | 2019-06-29 19:29:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 5,000 ms |
| コード長 | 505 bytes |
| コンパイル時間 | 1,903 ms |
| コンパイル使用メモリ | 200,740 KB |
| 最終ジャッジ日時 | 2025-01-07 05:43:55 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
int main() {
int N;
std::cin >> N;
std::vector<int> W(N);
for(auto&v:W)std::cin >> v;
int sum = std::accumulate(begin(W),end(W),0);
std::vector<std::vector<bool>> dp(N+1,std::vector<bool>(sum/2+1,0));
dp[0][0]=true;
for(int i=0;i<N;++i){
for(int j=0;j<=sum/2;++j){
if(W[i]<=j)
dp[i+1][j] = dp[i][j-W[i]] || dp[i][j];
else
dp[i+1][j] = dp[i][j];
}
}
bool ans = dp[N][sum/2] && !(sum&1);
std::cout << (ans?"possible":"impossible") << std::endl;
}
kakeyamay