結果
問題 |
No.643 Two Operations No.2
|
ユーザー |
![]() |
提出日時 | 2018-05-23 02:07:13 |
言語 | Perl (5.40.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 474 bytes |
コンパイル時間 | 49 ms |
コンパイル使用メモリ | 7,168 KB |
実行使用メモリ | 7,296 KB |
最終ジャッジ日時 | 2024-06-28 16:02:57 |
合計ジャッジ時間 | 865 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 WA * 2 |
コンパイルメッセージ
Main.pl syntax OK
ソースコード
#!/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