結果
問題 | No.4 おもりと天秤 |
ユーザー | keib |
提出日時 | 2019-03-06 10:33:21 |
言語 | Swift (5.10.0) |
結果 |
AC
|
実行時間 | 10 ms / 5,000 ms |
コード長 | 1,021 bytes |
コンパイル時間 | 1,701 ms |
コンパイル使用メモリ | 186,516 KB |
実行使用メモリ | 15,360 KB |
最終ジャッジ日時 | 2024-05-07 18:43:32 |
合計ジャッジ時間 | 2,781 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 10 ms
15,104 KB |
testcase_01 | AC | 9 ms
14,976 KB |
testcase_02 | AC | 9 ms
15,232 KB |
testcase_03 | AC | 9 ms
15,104 KB |
testcase_04 | AC | 9 ms
15,232 KB |
testcase_05 | AC | 9 ms
15,104 KB |
testcase_06 | AC | 9 ms
14,848 KB |
testcase_07 | AC | 9 ms
15,232 KB |
testcase_08 | AC | 9 ms
15,232 KB |
testcase_09 | AC | 9 ms
15,360 KB |
testcase_10 | AC | 9 ms
15,232 KB |
testcase_11 | AC | 9 ms
14,976 KB |
testcase_12 | AC | 8 ms
15,104 KB |
testcase_13 | AC | 10 ms
15,104 KB |
testcase_14 | AC | 9 ms
14,976 KB |
testcase_15 | AC | 10 ms
15,232 KB |
testcase_16 | AC | 9 ms
14,976 KB |
testcase_17 | AC | 9 ms
15,104 KB |
testcase_18 | AC | 10 ms
15,232 KB |
testcase_19 | AC | 9 ms
15,232 KB |
testcase_20 | AC | 9 ms
15,104 KB |
testcase_21 | AC | 9 ms
15,360 KB |
testcase_22 | AC | 10 ms
15,360 KB |
ソースコード
import Foundation let n = Int(readLine()!)! let weights = readLine()!.split(separator:" ").map { Int($0)! } var weightSum = 0 var maxWeight = 0 weights.forEach { weight in weightSum += weight maxWeight = Swift.max(weight, maxWeight) } if weightSum % 2 != 0 { print("impossible") exit(0) } let goal = weightSum / 2 if maxWeight > goal { print("impossible") exit(0) } var possibilities = Array<Int>(repeating: -1, count: goal + 1) weights.enumerated().forEach { i, weight in if possibilities[weight] < 0 { possibilities[weight] = i } for j in 1 ..< Swift.min(goal - weight + 1, possibilities.count) { if possibilities[j] < 0 { continue } if possibilities[j] >= i { continue } if possibilities[j + weight] >= 0 { continue } if j + weight == goal { print("possible") exit(0) } possibilities[j + weight] = i } } print("impossible") exit(0)