結果

問題 No.4 おもりと天秤
ユーザー ko_ki_leoko_ki_leo
提出日時 2015-10-11 20:19:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 500 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 143,096 KB
実行使用メモリ 8,348 KB
最終ジャッジ日時 2023-09-08 16:25:56
合計ジャッジ時間 2,183 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,160 KB
testcase_01 AC 4 ms
8,216 KB
testcase_02 AC 4 ms
8,336 KB
testcase_03 AC 4 ms
8,148 KB
testcase_04 AC 4 ms
8,160 KB
testcase_05 AC 7 ms
8,128 KB
testcase_06 AC 4 ms
8,344 KB
testcase_07 AC 8 ms
8,124 KB
testcase_08 AC 4 ms
8,348 KB
testcase_09 AC 4 ms
8,104 KB
testcase_10 AC 7 ms
8,156 KB
testcase_11 AC 4 ms
8,112 KB
testcase_12 AC 4 ms
8,132 KB
testcase_13 AC 4 ms
8,180 KB
testcase_14 AC 4 ms
8,108 KB
testcase_15 AC 4 ms
8,116 KB
testcase_16 AC 4 ms
8,180 KB
testcase_17 AC 4 ms
8,212 KB
testcase_18 AC 6 ms
8,160 KB
testcase_19 AC 7 ms
8,108 KB
testcase_20 AC 7 ms
8,148 KB
testcase_21 AC 7 ms
8,220 KB
testcase_22 AC 7 ms
8,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int n;
int data[111];
int memo[111][11111];

bool solve(int p, int w){

  if(p == n && w == 11111) return true;
  if(p == n) return false;
  if(~memo[p][w]) return memo[p][w];
  
  int ret = false;
  ret |= solve(p+1, w+data[p]) | solve(p+1, w-data[p]);

  return memo[p][w] = ret;
}

int main(){

  cin >> n;
  for(int i=0;i<n;i++) cin >> data[i];

  memset(memo, -1, sizeof(memo));
  if(solve(0, 11111)) puts("possible");
  else puts("impossible");

}
0