結果

問題 No.643 Two Operations No.2
ユーザー motimoti
提出日時 2018-05-23 02:07:13
言語 Perl
(5.38.2)
結果
WA  
実行時間 -
コード長 474 bytes
コンパイル時間 61 ms
コンパイル使用メモリ 6,300 KB
実行使用メモリ 6,392 KB
最終ジャッジ日時 2023-09-11 01:31:53
合計ジャッジ時間 1,022 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,116 KB
testcase_01 AC 14 ms
6,096 KB
testcase_02 AC 14 ms
6,292 KB
testcase_03 AC 14 ms
6,292 KB
testcase_04 AC 15 ms
6,180 KB
testcase_05 AC 14 ms
6,292 KB
testcase_06 WA -
testcase_07 AC 13 ms
6,112 KB
testcase_08 WA -
testcase_09 AC 14 ms
6,392 KB
testcase_10 AC 13 ms
6,212 KB
testcase_11 AC 14 ms
6,180 KB
testcase_12 AC 14 ms
6,204 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.pl syntax OK

ソースコード

diff #

#!/usr/bin/env perl

use strict;
use warnings;
use Data::Dumper;

my ($x, $y) = split / /, <>; chomp $y;

if ($x == $y) {
  print 0;
  exit;
}

my @q;
push @q, [$y, $x, 1];
push @q, [$x + $y, $x - $y, 1];
my %vis;
while (scalar @q) {
  my ($x, $y, $c) = @{shift @q};
  if ($x == $y) {
    print $c;
    exit;
  }
  my @mark = ($x, $y);
  if (!exists $vis{@mark}) {
    $vis{@mark} = 1;
    push @q, [$y, $x, $c + 1];
    push @q, [$x + $y, $x - $y, $c + 1];
  }
}

print -1
0