結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-04-03 20:38:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 5,000 ms |
| コード長 | 894 bytes |
| コンパイル時間 | 3,139 ms |
| コンパイル使用メモリ | 172,260 KB |
| 最終ジャッジ日時 | 2025-01-28 14:48:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <cmath>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)
int main(){
int n;
cin >> n;
vector<vector<bool>> dp(n+1,vector<bool> (20001));
int sum = 0;
vector<int> a(n);
rep(i,n){
cin >> a[i];
sum += a[i];
}
dp[0][0] = true;
for (int i = 0; i < n;i++){
for (int j = 0; j <= 10000;j++){
if (dp[i][j]){
dp[i+1][j] = true;
dp[i+1][j+a[i]] = true;
}
}
}
bool yes = false;
for (int w = 0; w <= 10000;w++){
if (dp[n][w] && w*2 == sum){
yes = true;
break;
}
}
if (yes) cout << "possible" << endl;
else cout << "impossible" << endl;
return 0;
}