Submission #10189095


Source Code Expand

Copy
<?php
list($H, $W) = ints();
$max = 0;
$five = false;
for($i = 0; $i < $H; $i++){
  $map[$i] = ints();
  $max = max(max($map[$i]), $max);
  for($j = 0; $j < $W; $j++)if($map[$i][$j]==5)$five = true;
}
if($max == 0){echo "Yes 0";exit;}
if($five == false){echo "No";exit;}
if(min($H, $W) > 1){
  $count = opToLower($map);
  echo "Yes ",$count+1,"\n";
}else{
  if($W == 1){
    for($y = 0; $y < $H; $y++)$row[0][] = $map[$y][0];
  }else{
    $row = $map;
  }
  $min = 10**10;
  for($i = 0; $i < count($row[0]); $i++){
    if($row[0][$i]==5){
      $left = [];
      $right = [];
      for($j = 0; $j < $i; $j++)$left[0][] = $row[0][$j];
      for($j = $i+1; $j < count($row[0]); $j++)$right[0][] = $row[0][$j];
      chmin($min, opToLower($right)+opToLower($left)+1);
    }
  }
  echo "Yes $min","\n";
}
function opToLower($map){
  $num = array_fill(0, 10, 0);
  for($i = 0; $i < count($map); $i++){
    for($j = 0; $j < count($map[0]); $j++){
      $num[$map[$i][$j]]++;
    }
  }
  $count = 0;
  if($num[7])chmax($count, 1);
  if($num[8])chmax($count, 2);
  if($num[6])chmax($count, 1);
  if($num[9])chmax($count, 3);
  if($num[3])chmax($count, 2);
  return $count;
}
//o($max);
//o($map);

function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function chmax(&$a,$b){if($a<$b){$a=$b;return 1;}return 0;}
function chmin(&$a,$b){if($a>$b){$a=$b;return 1;}return 0;}

function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array: ";
            echo implode(" ", addIndex($val))."\n";
        }else{
            echo "array:array\n";
            if(isCleanArray($val)){
                foreach($val as $row)echo implode(" ", addIndex($row))."\n";
            }else{
                foreach($val as $i => $row)echo "[".$i."] ".implode(" ", addIndex($row))."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}
function addIndex($val){
    if(!isCleanArray($val)){
        $val = array_map(function($k, $v){return $k.":".$v;}, array_keys($val), $val);
    }
    return $val;
}
function isCleanArray($array){
    $clean = true;
    $i = 0;
    foreach($array as $k => $v){
        if($k != $i++)$clean = false;
    }
    return $clean;
}
/**
 * 座圧対象の配列を渡すと以下の値を返す
 * ・圧縮された配列
 * ・復元用のMap
 * ・圧縮用のMap
 **/
function atsu($array){
    $a = array_flip($array);
    $fuku = array_flip($a);
    sort($fuku);
    $atsu = array_flip($fuku);
    foreach($array as $i => $val)$array[$i] = $atsu[$val];
    return [$array, $fuku, $atsu];
}
//配列の最大公約数
function gcdAll($array){
    $gcd = $array[0];
    for($i = 1; $i < count($array); $i++){
        $gcd = gcd($gcd, $array[$i]);
    }
    return $gcd;
}

//最大公約数
function gcd($m, $n){
    if(!$n)return $m;
    return gcd($n, $m % $n);
}

//配列の最小公倍数
function lcmAll($array){
    $lcm = $array[0];
    for($i = 1; $i < count($array); $i++){
        $lcm = lcm($lcm, $array[$i]);
    }
    return $lcm;
}

//最小公倍数
function lcm($a, $b) {
    return $a / gcd($a, $b) * $b;
}
//ビットカウント-1の数を数える
function popcount($x){
    $con = 0;
    while ($x) {
        $x &= $x-1;
        ++$con;
    }
    return $con;
}

Submission Info

Submission Time
Task B - 10 puzzle
User yoichiro
Language PHP7 (7.0.15)
Score 0
Code Size 3711 Byte
Status
Exec Time 17 ms
Memory 4856 KB

Test Cases

Set Name Score / Max Score Test Cases
All 0 / 100 0-sample-1, 0-sample-2, 0-sample-3, 0-sample-4, 1-random-small-0, 1-random-small-1, 1-random-small-2, 1-random-small-3, 1-random-small-4, 2-random-large-0, 2-random-large-1, 2-random-large-2, 2-random-large-3, 2-random-large-4, 3-random-line-0, 3-random-line-1, 3-random-line-10, 3-random-line-11, 3-random-line-12, 3-random-line-13, 3-random-line-14, 3-random-line-15, 3-random-line-16, 3-random-line-2, 3-random-line-3, 3-random-line-4, 3-random-line-5, 3-random-line-6, 3-random-line-7, 3-random-line-8, 3-random-line-9, 4-zero-0, 4-zero-1, 4-zero-2, 5-no-0, 5-no-1, 5-no-2, 6-minimum-0, 6-minimum-1, 6-minimum-2, 9-hand-0, 9-hand-1, 9-hand-2, 9-hand-3, 9-hand-4
Case Name Status Exec Time Memory
0-sample-1 17 ms 4856 KB
0-sample-2 9 ms 4604 KB
0-sample-3 9 ms 4732 KB
0-sample-4 9 ms 4604 KB
1-random-small-0 9 ms 4604 KB
1-random-small-1 9 ms 4604 KB
1-random-small-2 9 ms 4604 KB
1-random-small-3 9 ms 4604 KB
1-random-small-4 9 ms 4604 KB
2-random-large-0 11 ms 4604 KB
2-random-large-1 11 ms 4604 KB
2-random-large-2 11 ms 4604 KB
2-random-large-3 11 ms 4604 KB
2-random-large-4 11 ms 4604 KB
3-random-line-0 9 ms 4604 KB
3-random-line-1 9 ms 4604 KB
3-random-line-10 9 ms 4604 KB
3-random-line-11 9 ms 4604 KB
3-random-line-12 9 ms 4604 KB
3-random-line-13 9 ms 4604 KB
3-random-line-14 9 ms 4604 KB
3-random-line-15 9 ms 4604 KB
3-random-line-16 9 ms 4604 KB
3-random-line-2 9 ms 4604 KB
3-random-line-3 9 ms 4604 KB
3-random-line-4 9 ms 4604 KB
3-random-line-5 9 ms 4604 KB
3-random-line-6 9 ms 4604 KB
3-random-line-7 9 ms 4604 KB
3-random-line-8 9 ms 4604 KB
3-random-line-9 9 ms 4604 KB
4-zero-0 10 ms 4604 KB
4-zero-1 9 ms 4604 KB
4-zero-2 9 ms 4604 KB
5-no-0 10 ms 4604 KB
5-no-1 9 ms 4604 KB
5-no-2 9 ms 4604 KB
6-minimum-0 9 ms 4604 KB
6-minimum-1 9 ms 4604 KB
6-minimum-2 9 ms 4604 KB
9-hand-0 9 ms 4604 KB
9-hand-1 9 ms 4604 KB
9-hand-2 9 ms 4604 KB
9-hand-3 9 ms 4604 KB
9-hand-4 9 ms 4604 KB