結果
| 問題 | No.4 おもりと天秤 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-07-28 19:39:12 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 107 ms / 5,000 ms | 
| コード長 | 548 bytes | 
| コンパイル時間 | 106 ms | 
| コンパイル使用メモリ | 12,288 KB | 
| 実行使用メモリ | 18,176 KB | 
| 最終ジャッジ日時 | 2025-07-28 19:39:15 | 
| 合計ジャッジ時間 | 2,590 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
def balance(weights):
    n = len(weights)  
    total_sum = sum(weights)
    if total_sum % 2 == 1:  
        return "impossible"
    dp = [[False] * 10009 for _ in range(n + 1)]
    dp[0][0] = True  
    for i in range(n):
        for j in range(10000 + 1):
            if not dp[i][j]:
                continue
            dp[i + 1][j] = True  
            dp[i + 1][j + weights[i]] = True  
    return "possible" if dp[n][total_sum // 2] else "impossible"
n = int(input())
weights = list(map(int, input().split()))
print(balance(weights))
            
            
            
        