結果
| 問題 |
No.4 おもりと天秤
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-10 22:10:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 990 bytes |
| コンパイル時間 | 1,479 ms |
| コンパイル使用メモリ | 169,444 KB |
| 実行使用メモリ | 10,272 KB |
| 最終ジャッジ日時 | 2024-07-08 09:39:06 |
| 合計ジャッジ時間 | 8,131 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 18 TLE * 1 -- * 4 |
ソースコード
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
vector<int>vec;
int avg;
int N;
bool dfs(int index, int now) {
int n = vec[index];
int add_case = now + n;
if (now == avg) return true;
if (now > avg) return false;
if (index < N) {
return (dfs(index+1, add_case) || dfs(index+1, now));
} else {
return false;
}
}
int main()
{
cin >> N;
vec.resize(N);
int sum = 0;
for (int i=0; i<N; i++) {
cin >> vec.at(i);
sum += vec[i];
}
if (sum % 2 != 0) {
cout << "impossible" << endl;
} else {
avg = sum/2;
if (dfs(0, 0)) {
cout << "possible" << endl;
} else {
cout << "impossible" << endl;
}
}
return 0;
}