結果

問題 No.5 数字のブロック
ユーザー shiCanoko_oshiCanoko_o
提出日時 2019-05-23 19:40:25
言語 Perl
(5.38.2)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 812 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 5,444 KB
実行使用メモリ 7,880 KB
最終ジャッジ日時 2023-10-17 11:35:39
合計ジャッジ時間 1,382 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,640 KB
testcase_01 AC 4 ms
5,640 KB
testcase_02 AC 3 ms
5,640 KB
testcase_03 AC 9 ms
7,020 KB
testcase_04 AC 7 ms
6,740 KB
testcase_05 AC 11 ms
7,416 KB
testcase_06 AC 7 ms
6,788 KB
testcase_07 AC 6 ms
6,584 KB
testcase_08 AC 8 ms
6,936 KB
testcase_09 AC 5 ms
6,096 KB
testcase_10 AC 10 ms
7,568 KB
testcase_11 AC 7 ms
6,564 KB
testcase_12 AC 8 ms
7,072 KB
testcase_13 AC 9 ms
7,384 KB
testcase_14 AC 3 ms
5,656 KB
testcase_15 AC 4 ms
5,688 KB
testcase_16 AC 9 ms
7,456 KB
testcase_17 AC 12 ms
7,768 KB
testcase_18 AC 10 ms
7,628 KB
testcase_19 AC 12 ms
7,880 KB
testcase_20 AC 3 ms
5,640 KB
testcase_21 AC 4 ms
5,640 KB
testcase_22 AC 3 ms
5,640 KB
testcase_23 AC 3 ms
5,640 KB
testcase_24 AC 4 ms
5,700 KB
testcase_25 AC 3 ms
5,756 KB
testcase_26 AC 3 ms
5,640 KB
testcase_27 AC 3 ms
5,640 KB
testcase_28 AC 3 ms
5,640 KB
testcase_29 AC 7 ms
6,728 KB
testcase_30 AC 5 ms
6,172 KB
testcase_31 AC 3 ms
5,640 KB
testcase_32 AC 4 ms
5,640 KB
testcase_33 AC 3 ms
5,640 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

my $weight_box = <>;#箱の幅
my $total_blocks = <>;#ブロックの数
my $weight_blocks = <>;#各ブロックの幅
chomp ($weight_box, $total_blocks, $weight_blocks);

my @blocks = split (/ /, $weight_blocks);#各ブロックを配列に入れる
my @sorted_weight_blocks = sort{$a <=> $b}@blocks;#配列に入れたブロックを小さい順に並べる

my $sum1 = 0;
$sum1 += $_ for @sorted_weight_blocks;

if($sum1 < $weight_box){
    print "$total_blocks\n";
}else{
    my $sum = 0;
    my $count = 0;

    for (my $num = 0; $sum + $sorted_weight_blocks[$num] <= $weight_box; $num++){
        if($sum + $sorted_weight_blocks[$num] == $weight_box){
            $count++;
            last;
        }{
        $sum += $sorted_weight_blocks[$num];
        }
        $count++;
    }

    print "$count\n"
}
0