結果
問題 | No.4 おもりと天秤 |
ユーザー | shin |
提出日時 | 2022-10-12 23:06:33 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 824 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 10,788 KB |
実行使用メモリ | 12,608 KB |
最終ジャッジ日時 | 2023-09-08 18:41:21 |
合計ジャッジ時間 | 7,340 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,960 KB |
testcase_01 | AC | 15 ms
7,900 KB |
testcase_02 | AC | 24 ms
7,792 KB |
testcase_03 | AC | 15 ms
7,740 KB |
testcase_04 | AC | 16 ms
7,780 KB |
testcase_05 | AC | 16 ms
7,816 KB |
testcase_06 | AC | 15 ms
7,752 KB |
testcase_07 | AC | 23 ms
7,932 KB |
testcase_08 | AC | 15 ms
7,848 KB |
testcase_09 | AC | 15 ms
7,780 KB |
testcase_10 | AC | 23 ms
7,752 KB |
testcase_11 | AC | 15 ms
7,760 KB |
testcase_12 | AC | 16 ms
7,800 KB |
testcase_13 | AC | 15 ms
7,756 KB |
testcase_14 | AC | 16 ms
7,744 KB |
testcase_15 | AC | 16 ms
7,748 KB |
testcase_16 | AC | 15 ms
7,736 KB |
testcase_17 | AC | 16 ms
7,940 KB |
testcase_18 | TLE | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
ソースコード
#おもりと天秤 N = 0 W = [] total = 0 def sumup(s , sum): if s > N // 2 and sum == 0: return False else: for i in range(s , N): sum += W[i] if sum == total: return True elif sum < total: if i + 1 < N: if sumup(i + 1 , sum): return True else: sum -= W[i] return sumup(i + 1 , sum) else: return False N = int(input()) W = list(map(int , input().split())) for i in W: total += i W.sort() if total % 2 == 1: print("impossible") else: total = total // 2 if sumup(0 , 0): print("possible") else: print("impossible")