結果

問題 No.429 CupShuffle
ユーザー papinianus
提出日時 2016-10-03 09:19:09
言語 PHP
(843.2)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 892 bytes
コンパイル時間 1,186 ms
コンパイル使用メモリ 30,932 KB
実行使用メモリ 71,436 KB
最終ジャッジ日時 2024-11-21 15:07:29
合計ジャッジ時間 2,868 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 16
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
list($n, $k, $x) = explode(" ",trim(fgets(STDIN)));
$start = range(1, $n);
$manipulate = [];
for($i = $k;$i;$i--)
{
    $manipulate[] = explode(" ",trim(fgets(STDIN)));
}
$goal = explode(" ",trim(fgets(STDIN)));
$start = exchange($start, array_slice($manipulate,0,$x - 1));
$goal = exchange($goal, array_reverse(array_slice($manipulate,$x)));

$diff = diff($start, $goal);
sort($diff);
echo (implode(" ",$diff)).PHP_EOL;

function exchange($base, $acts)
{
    foreach($acts as $act)
    {
        $a = $act[0]-1; //num to index
        $b = $act[1]-1; //num to index
        $tmp = $base[$b];
        $base[$b] = $base[$a];
        $base[$a] = $tmp;
    }
    return $base;
}

function diff($a, $b)
{
    $res=[];
    $len = count($a);
    for($i=0;$i < $len;$i++)
    {
        if($a[$i] != $b[$i])
        {
            $res[] = $i+1; //index to num
        }
    }
    return $res;
}
0