Submission #1690579


Source Code Expand

<?php

$row1 = trim(fgets(STDIN));

list($n, $m) = explode(" ", $row1);

$row2 = trim(fgets(STDIN));

$numbers = explode(" ", $row2);

$x = 5;

$bound_low = 1;
$bound_high = $m;

while(true)
{
    $score = score($x);
    $higher = score($x+1);
    $lower = score($x-1);
    if (($score <= $higher && ($score <= $lower)))
    {
        //finished
        break;
    }
    
    
    if ($lower < $score)
    {
        $x = (($x + $bound_low)/2);
        $bound_high = $x;
    }
    
    if ($higher < $score)
    {
      
        $x = ($x + $bound_high)/2;
        $bound_low = $x;
    }

}

echo $score . "\n";


function score($x) {
    global $numbers;
    global $m;

    $press = 0;
    $current = 1;

    foreach ($numbers as $number) {
        if ($current == $number) {
            continue;
        }

        if (($x > $number) && ($x > $current)) {
            $current = $x;
            $press++;
        }

        
        if ($current < $number) {
        
            $press += $number - $current;
        }
        else
        {
            $press += $number + $m - $current;
        }
    }
    
    return $press;
}

Submission Info

Submission Time
Task E - guruguru
User paullb
Language PHP (5.6.30)
Score 0
Code Size 1209 Byte
Status WA
Exec Time 2105 ms
Memory 21552 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 1
WA × 1
AC × 1
WA × 12
TLE × 9
Set Name Test Cases
Sample sample1.txt, sample2.txt
All half0.txt, half1.txt, half2.txt, half3.txt, half4.txt, min_m.txt, min_n.txt, mx0.txt, mx1.txt, mx2.txt, rnd0.txt, rnd1.txt, rnd2.txt, rnd3.txt, rnd4.txt, rnd5.txt, rnd6.txt, rnd7.txt, rnd8.txt, rnd9.txt, sample1.txt, sample2.txt
Case Name Status Exec Time Memory
half0.txt WA 64 ms 8292 KB
half1.txt TLE 2104 ms 5180 KB
half2.txt TLE 2105 ms 11384 KB
half3.txt TLE 2105 ms 16732 KB
half4.txt TLE 2105 ms 17220 KB
min_m.txt TLE 2104 ms 3576 KB
min_n.txt WA 10 ms 3576 KB
mx0.txt WA 282 ms 21552 KB
mx1.txt WA 346 ms 21552 KB
mx2.txt WA 118 ms 21552 KB
rnd0.txt WA 10 ms 3576 KB
rnd1.txt WA 10 ms 3576 KB
rnd2.txt TLE 2104 ms 4340 KB
rnd3.txt TLE 2104 ms 6684 KB
rnd4.txt TLE 2105 ms 18000 KB
rnd5.txt TLE 2104 ms 4212 KB
rnd6.txt WA 11 ms 3576 KB
rnd7.txt WA 17 ms 3828 KB
rnd8.txt WA 24 ms 4940 KB
rnd9.txt WA 10 ms 3576 KB
sample1.txt WA 10 ms 3576 KB
sample2.txt AC 10 ms 3576 KB