結果

問題 No.561 東京と京都
ユーザー motimoti
提出日時 2018-05-30 03:00:58
言語 Perl
(5.38.2)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 630 bytes
コンパイル時間 744 ms
コンパイル使用メモリ 7,076 KB
実行使用メモリ 5,132 KB
最終ジャッジ日時 2023-09-12 20:34:02
合計ジャッジ時間 1,442 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
4,840 KB
testcase_01 AC 5 ms
4,964 KB
testcase_02 AC 5 ms
4,836 KB
testcase_03 AC 5 ms
4,940 KB
testcase_04 AC 5 ms
4,920 KB
testcase_05 AC 5 ms
4,840 KB
testcase_06 AC 5 ms
5,020 KB
testcase_07 AC 5 ms
5,020 KB
testcase_08 AC 5 ms
4,980 KB
testcase_09 AC 5 ms
5,052 KB
testcase_10 AC 5 ms
5,076 KB
testcase_11 AC 5 ms
4,968 KB
testcase_12 AC 5 ms
5,084 KB
testcase_13 AC 5 ms
4,840 KB
testcase_14 AC 5 ms
5,132 KB
testcase_15 AC 6 ms
5,124 KB
testcase_16 AC 5 ms
4,920 KB
testcase_17 AC 5 ms
5,032 KB
testcase_18 AC 5 ms
4,920 KB
testcase_19 AC 5 ms
4,864 KB
testcase_20 AC 5 ms
4,920 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/env perl

use strict;
use warnings;

my ($n, $d) = split / /, <>;
chomp $d;

my @dp;
$dp[0][0] = 0;
$dp[0][1] = -999999999999999999;
for my $i (1..110) {
  for my $j (0..1) {
    $dp[$i][$j] = -1;
  }
}
for (my $i = 0; $i < $n; $i++) {
  my ($t, $k) = split / /, <>;
  chomp $k;

  my ($x, $y) = ($dp[$i][0] + $t, $dp[$i][1] + $t - $d);
  $dp[$i + 1][0] = $x if $x >= $y;
  $dp[$i + 1][0] = $y if $x < $y;

  my ($z, $w) = ($dp[$i][1] + $k, $dp[$i][0] + $k - $d);
  $dp[$i + 1][1] = $z if $z >= $w;
  $dp[$i + 1][1] = $w if $z < $w;
}

if ($dp[$n][0] >= $dp[$n][1]) {
  print $dp[$n][0];
} else {
  print $dp[$n][1];
}
0