結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
dgd1724
|
| 提出日時 | 2016-11-22 06:49:02 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,103 bytes |
| コンパイル時間 | 1,399 ms |
| コンパイル使用メモリ | 159,188 KB |
| 実行使用メモリ | 10,496 KB |
| 最終ジャッジ日時 | 2024-11-27 09:36:19 |
| 合計ジャッジ時間 | 56,186 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 TLE * 9 |
ソースコード
#include <bits/stdc++.h>
//const static double de_PI = 3.14159265358979323846;
//const static double de_EPS = 0.000001;
//const static int de_MOD = 1000000007;
//const static int de_MAX = 999999999;
//const static int de_MIN = -999999999;
inline void Increase_Binary(std::bitset<100> &a) {
unsigned int i = 0;
while (1) {
if (a[i] == 0) {
a[i] = 1;
break;
}
else {
a[i] = 0;
i++;
}
}
}
int main(void) {
//std::ifstream inf("123.txt"); std::cin.rdbuf(inf.rdbuf());
int N = 0;
std::cin >> N;
std::valarray<int> W(N);
for (int i = 0; i < N; i++) { std::cin >> W[i]; }
if (W.sum() % 2 != 0) {
std::cout << "impossible" << std::endl;
return 0;
}
int half = N / 2, count = 0, sum = 0, compare = W.sum() / 2;
std::bitset<100> flg;
while (1) {
Increase_Binary(flg);
count = flg.count();
if (count == N) { break; }
if (count > half) { continue; }
sum = 0;
for (int i = 0; i < N; i++) {
if (flg[i]) { sum += W[i]; }
}
if (sum == compare) {
std::cout << "possible" << std::endl;
return 0;
}
}
std::cout << "impossible" << std::endl;
}
dgd1724