結果

問題 No.32 貯金箱の憂鬱
ユーザー kuroi_13kuroi_13
提出日時 2017-01-25 12:58:23
言語 Perl
(5.38.2)
結果
TLE  
実行時間 -
コード長 552 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 7,104 KB
実行使用メモリ 31,088 KB
最終ジャッジ日時 2023-08-24 22:08:16
合計ジャッジ時間 9,668 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
5,324 KB
testcase_01 AC 4 ms
4,836 KB
testcase_02 AC 14 ms
5,460 KB
testcase_03 AC 311 ms
9,464 KB
testcase_04 AC 415 ms
10,464 KB
testcase_05 AC 304 ms
9,432 KB
testcase_06 AC 928 ms
13,292 KB
testcase_07 AC 496 ms
10,944 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

use strict;
use warnings;

my @coins = (100, 25, 1, 1000);
my($in, $tgt) = (0, 0);
for(0..2){
    my $in = <STDIN>;
    chomp $in;
    $tgt += ($in*$coins[$_]);
}

my %f = (0 => 0);
my %n_f = %f;
my $val = 0;
my $quo = 0;
while(!defined($f{$tgt})){
  for my $i (keys %f){
    for my $j (@coins){
      $val = $i+$j;
      $quo = $j == 1000 ? $f{$i} : $f{$i}+1;
      if(!defined($n_f{$val})){
        $n_f{$val} = $quo;
      }else{
        if($quo < $n_f{$val}){
          $n_f{$val} = $quo;
        }
      }
    }
  }
  %f = %n_f;
}

print $f{$tgt};
0