結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
hibari2357
|
| 提出日時 | 2019-03-30 07:59:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 1,007 bytes |
| コンパイル時間 | 1,146 ms |
| コンパイル使用メモリ | 112,068 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 21:40:49 |
| 合計ジャッジ時間 | 2,021 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001
int main() {
int N; cin >> N;
vector<int> W(N);
int s = 0;
for(int &w:W){
cin >> w;
s += w;
}
int x = s/2;
if(x*2!=s){
cout << "impossible" << endl;
return 0;
}
vector<vector<bool>> dp(N+1, vector<bool>(10001));
dp[0][0] = 1;
for(int i=0; i<N; i++){
for(int j=0; j<=10000; j++){
if(j-W[i+1]>=0) dp[i+1][j] = dp[i][j] | dp[i][j-W[i+1]];
else dp[i+1][j] = dp[i][j];
}
}
if(dp[N][x]) cout << "possible" << endl;
else cout << "impossible" << endl;
return 0;
}
hibari2357