結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,940 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);
    }
  }
}
0