結果

問題 No.4 おもりと天秤
ユーザー sannennemutarousannennemutarou
提出日時 2021-02-10 22:10:58
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 990 bytes
コンパイル時間 1,639 ms
コンパイル使用メモリ 167,896 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-09-22 18:24:10
合計ジャッジ時間 8,664 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0