結果

問題 No.4 おもりと天秤
ユーザー OhashiReonOhashiReon
提出日時 2022-12-23 06:40:11
言語 Nim
(2.0.2)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 546 bytes
コンパイル時間 3,516 ms
コンパイル使用メモリ 66,432 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 04:12:04
合計ジャッジ時間 4,715 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 5 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 4 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 AC 5 ms
5,376 KB
testcase_22 AC 4 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(3, 8) Warning: imported and not used: 'bitops' [UnusedImport]

ソースコード

diff #

import sequtils
import strutils
import bitops
import math
import deques

proc get[T](s:seq[T],index :int):T=
    if index < 0 or s.len <= index:
        return false
    return s[index]

var n = stdin.readLine.parseInt
var a = stdin.readLine.split.map parseInt
var half = (a.sum div 2)
var DP = newSeqWith(n+1,newSeqWith(half+1,false))
DP[0][0] = true

for i in 1..n:
    for j in 0..half:
        DP[i][j] = DP[i-1][j] or DP[i-1].get(j-a[i-1])

if a.sum mod 2 == 1:
    echo "impossible"
else:
    echo if DP[n][half]:"possible"else:"impossible"
0