結果

問題 No.107 モンスター
ユーザー kuroi_13kuroi_13
提出日時 2017-03-24 11:48:28
言語 Perl
(5.38.2)
結果
AC  
実行時間 176 ms / 5,000 ms
コード長 712 bytes
コンパイル時間 401 ms
コンパイル使用メモリ 5,340 KB
実行使用メモリ 16,452 KB
最終ジャッジ日時 2023-09-20 05:24:19
合計ジャッジ時間 2,861 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,952 KB
testcase_01 AC 5 ms
5,048 KB
testcase_02 AC 5 ms
5,016 KB
testcase_03 AC 5 ms
4,868 KB
testcase_04 AC 5 ms
5,088 KB
testcase_05 AC 5 ms
4,956 KB
testcase_06 AC 5 ms
4,820 KB
testcase_07 AC 5 ms
5,016 KB
testcase_08 AC 5 ms
4,976 KB
testcase_09 AC 5 ms
4,816 KB
testcase_10 AC 5 ms
5,092 KB
testcase_11 AC 5 ms
4,840 KB
testcase_12 AC 5 ms
4,948 KB
testcase_13 AC 59 ms
7,800 KB
testcase_14 AC 124 ms
10,752 KB
testcase_15 AC 125 ms
10,784 KB
testcase_16 AC 5 ms
4,972 KB
testcase_17 AC 22 ms
6,276 KB
testcase_18 AC 58 ms
16,172 KB
testcase_19 AC 58 ms
16,172 KB
testcase_20 AC 81 ms
7,828 KB
testcase_21 AC 58 ms
7,980 KB
testcase_22 AC 109 ms
10,752 KB
testcase_23 AC 176 ms
16,452 KB
testcase_24 AC 111 ms
16,356 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

use strict;
use warnings;

my $m_num = <>;
my @mons = split ' ', <>;
my %point = (pres => 100, max => 100);

my @dp;
for(my $i = 0; $i < 1<<$m_num; $i++){
  $dp[$i] = [0, 0];
}
$dp[0] = [100, 100];

my $ni = 0;
for(my $i = 0; $i < 1<<$m_num; $i++){
  next if($dp[$i][0] < 1);
  for my $j (0..$m_num-1){
    next if(($i>>$j) % 2);

    my @np = @{$dp[$i]};
    if(0 < $mons[$j]){
      $np[0] += $mons[$j];
      $np[0] = $np[1] < $np[0] ? $np[1]: $np[0];
    }else{
      if($np[0] + $mons[$j] > 0){
        $np[0] += $mons[$j];
        $np[1] += 100;
      }else{
        $np[0] = 0;
      }
    }
    $ni = $i | 1 << $j;
    $dp[$ni] = $dp[$ni][0] < $np[0] ? \@np : $dp[$ni];
  }
}
print $dp[(1<<$m_num)-1][0];
0