結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
めうめう🎒
|
| 提出日時 | 2016-03-13 22:43:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 930 bytes |
| コンパイル時間 | 794 ms |
| コンパイル使用メモリ | 75,264 KB |
| 実行使用メモリ | 10,144 KB |
| 最終ジャッジ日時 | 2024-09-25 11:36:40 |
| 合計ジャッジ時間 | 7,401 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 4 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)
int n,w[101],make_num,max_make[101];
bool bfs(int now,int sum){
if(sum == make_num) {
make_num = 0;
return true;
}
if(sum > make_num || now == -1 || sum + max_make[now] < make_num) return false;
return (bfs(now - 1,sum + w[now]) || bfs(now - 1,sum));
}
int main() {
bool ans = false;
cin >> n;
for(int i = 0;i < n;i++){
cin >> w[i];
make_num += w[i];
if(i == 0) max_make[i] = w[i];
else max_make[i] = max_make[i-1] + w[i];
}
sort(w,w + n);
if(make_num % 2 == 1) ans = false;
else{
make_num = make_num / 2;
ans = bfs(n-1,0);
}
if(ans) cout << "possible" << endl;
else cout << "impossible" << endl;
return 0;
}
めうめう🎒