結果

問題 No.4 おもりと天秤
ユーザー cimjnuqycimjnuqy
提出日時 2016-04-18 22:58:24
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,114 bytes
コンパイル時間 597 ms
コンパイル使用メモリ 71,592 KB
実行使用メモリ 10,272 KB
最終ジャッジ日時 2024-04-15 03:40:26
合計ジャッジ時間 7,159 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
  int n;
  vector<int> vec;
  cin >> n;
  int tmp;
  int sum;
  sum = 0;
  for(int i=0;i<n;i++){
    cin >> tmp;
    sum += tmp;
    vec.push_back(tmp);
  }
  
  if(sum % 2 == 1){
    cout << "impossible" << endl;
    return 0;
  }
  
  sort(vec.begin(), vec.end());
  int a = sum / 2;
  int b;
  b = 0;
  
  vector< vector<int> >  vecs;
  vector<int> side1;
  vector<int> side2;
  
  side1.push_back(0);//sum
  side1.push_back(1);//nextIndex
  side2.push_back(vec[1]);//sum
  side2.push_back(1);//nextIndex
  vecs.push_back(side1);
  vecs.push_back(side2);
  
  //覚えたての深さ優先探索を使う  
  while(vecs.size() > 0){
    vector<int> side3;
    side3 = vecs.back();
    vecs.pop_back();
    
    if(side3[0] == a){
      cout << "possible" << endl;
      return 0;
    }else if(side3[0] < a && side3[1] < n){
      int index = side3[1];
      side3[1]++;
      vecs.push_back(side3);
      side3[0] += vec[index];
      vecs.push_back(side3);
    }
  }
  cout << "impossible" << endl;
  return 0;
  
}
0