結果

問題 No.4 おもりと天秤
ユーザー satou_a_mansatou_a_man
提出日時 2018-11-12 19:39:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 25 ms / 5,000 ms
コード長 1,067 bytes
コンパイル時間 2,815 ms
コンパイル使用メモリ 145,892 KB
実行使用メモリ 13,548 KB
最終ジャッジ日時 2023-08-25 13:43:39
合計ジャッジ時間 3,239 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
13,484 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 9 ms
13,216 KB
testcase_03 AC 8 ms
13,284 KB
testcase_04 AC 9 ms
13,236 KB
testcase_05 AC 25 ms
13,548 KB
testcase_06 AC 6 ms
13,284 KB
testcase_07 AC 25 ms
13,292 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 25 ms
13,540 KB
testcase_10 AC 24 ms
13,296 KB
testcase_11 AC 8 ms
13,240 KB
testcase_12 AC 6 ms
13,436 KB
testcase_13 AC 7 ms
13,480 KB
testcase_14 AC 7 ms
13,220 KB
testcase_15 AC 7 ms
13,280 KB
testcase_16 AC 8 ms
13,272 KB
testcase_17 AC 7 ms
13,296 KB
testcase_18 AC 25 ms
13,220 KB
testcase_19 AC 25 ms
13,260 KB
testcase_20 AC 25 ms
13,288 KB
testcase_21 AC 25 ms
13,356 KB
testcase_22 AC 24 ms
13,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)
bool dp[101][100000];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  cin>>n;
  vector<int> ws(n+1);
  rep(i,n)cin>>ws[i+1];
  int s = accumulate(ws.begin(),ws.end(),0);
  if(s%2==1) {
    cout << "impossible"<<endl;
    return 0;
  }
  memset(dp,false,sizeof(dp));
  rep(i,n+1) dp[i][0] = true;
  repeat(i,1,n+1) {
    repeat(w,1,100000) {
      dp[i][w] = dp[i-1][w];
      if(w-ws[i]>=0&&dp[i-1][w-ws[i]]) {
        dp[i][w] = true;
      }
    }
  }
  // rep(i,6) {
  //   rep(w,6) {
  //     if(dp[i][w]) cout << "true ";
  //     else cout << "false ";
  //   }
  //   cout << endl;
  // }
  // cout << "s=" << s << endl;
  if(dp[n][s/2]) {
    cout << "possible" << endl;
  } else {
    cout << "impossible" << endl;
  }
  return 0;
}
0