結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2022-01-06 20:22:20 |
言語 | TypeScript (5.7.2) |
結果 |
AC
|
実行時間 | 77 ms / 5,000 ms |
コード長 | 502 bytes |
コンパイル時間 | 8,263 ms |
コンパイル使用メモリ | 230,884 KB |
実行使用メモリ | 43,136 KB |
最終ジャッジ日時 | 2024-12-31 16:43:55 |
合計ジャッジ時間 | 10,725 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
function main(input) { const n = Number(input[0]); const w = input[1].split(" ").map(x=>Number(x)); const b = w.reduce((sum, x) => sum + x); if(b % 2 === 1) { console.log("impossible"); return; } const dp = new Array(b+1).fill(false); for(let i=0; i<n; i++) { for(let j=b; j>=0; j--) { if(dp[j]) dp[j+w[i]] = true; } dp[w[i]] = true; } console.log(dp[b/2] ? "possible" : "impossible"); } main(require("fs").readFileSync("/dev/stdin", "utf8").split("\n"));