結果

問題 No.4 おもりと天秤
ユーザー mh72012246mh72012246
提出日時 2016-10-18 18:43:35
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 777 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 71,152 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2024-05-02 02:42:51
合計ジャッジ時間 7,427 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream>   // istringstream
#include <algorithm> // sort
#include <utility>   // pair
#include <cfloat>    // DBL_MAX

typedef long long ll;
using namespace std;

bool rec(vector<int> vec, int idx, int N, int tgt){
  if(idx >= N || tgt < 0){ return false; }
  if(vec[idx] == tgt) { return true; }

  return rec(vec, idx+1, N, tgt-vec[idx])
    || rec(vec, idx+1, N, tgt);
}

int main(){
  int N; // [100]
  cin >> N;

  vector<int> weights (N); // [100]
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> weights[i];
    sum += weights[i];
  }

  //// main
  if(sum%2 || !rec(weights, 0, N, sum/2)){
    cout << "impossible" << endl;
  } else {
    cout << "possible" << endl;
  }

  return 0;
}
0