結果
| 問題 |
No.5 数字のブロック
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-12-13 08:22:32 |
| 言語 | TypeScript (5.7.2) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 691 bytes |
| コンパイル時間 | 8,178 ms |
| コンパイル使用メモリ | 228,748 KB |
| 実行使用メモリ | 47,728 KB |
| 最終ジャッジ日時 | 2024-12-31 16:48:22 |
| 合計ジャッジ時間 | 11,728 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 24 WA * 10 |
ソースコード
function Main(input: string): void {
const inputArr: string[] = input.split('\n');
const boxWidth: number = parseInt(inputArr[0]);
const blocksWidth: number[] = inputArr[2].split(' ')
.map(str => parseInt(str))
.sort((a, b) => a - b);
let sum = 0;
// 何個入るか をindexを使って表現したいが、ループ途中でbreakもしたいのでArray.forEach()が使えない
// そのため、 for of + Object.entries()を採用
for (const [index, blockWidth] of Object.entries(blocksWidth)) {
sum += blockWidth;
if (sum > boxWidth) {
console.log(parseInt(index));
break;
}
}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));