p_id
stringlengths 6
6
| language
stringclasses 10
values | status
stringclasses 2
values | code
stringlengths 1
563k
| prompt
stringlengths 113
563k
| answer
stringclasses 2
values |
---|---|---|---|---|---|
p03455 | PHP | Accepted | <?php
fscanf(STDIN, '%d %d', $a, $b);
if (($a*$b)%2===0){
echo 'Even' . "\n";
}else{
echo 'Odd' . "\n";
} | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, '%d %d', $a, $b);
if (($a*$b)%2===0){
echo 'Even' . "\n";
}else{
echo 'Odd' . "\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02394 | PHP | Accepted | <?php
fscanf(STDIN,"%d %d %d %d %d", $w, $h, $x, $y, $r);
$x1 = $w - $x;
$x2 = $x;
$y1 = $h - $y;
$y2 = $y;
if($x1 >= $r && $x2 >= $r && $y1 >= $r && $y2 >= $r)
echo "Yes"."\n";
else
echo "No"."\n";
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d %d %d %d %d", $w, $h, $x, $y, $r);
$x1 = $w - $x;
$x2 = $x;
$y1 = $h - $y;
$y2 = $y;
if($x1 >= $r && $x2 >= $r && $y1 >= $r && $y2 >= $r)
echo "Yes"."\n";
else
echo "No"."\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03209 | PHP | Accepted | <?php
fscanf(STDIN, "%d%d", $N, $X);
$dp[0] = 1;
$p[0] = 1;
for($i = 1; $i <= 50; $i++){
$dp[$i] = $dp[$i - 1] * 2 + 3;
$p[$i] = $p[$i - 1] * 2 + 1;
}
echo dfs($N, $X);
function dfs($N, $X){
global $dp, $p;
if($X >= $dp[$N])return $p[$N];
if($X <= 0)return 0;
if($N == 0)return 1;
$sum = dfs($N - 1, $X - 1);
if($X >= $dp[$N - 1] + 2)$sum++;
$sum += dfs($N - 1, $X - 1 - $dp[$N-1] - 1);
return $sum;
}
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d%d", $N, $X);
$dp[0] = 1;
$p[0] = 1;
for($i = 1; $i <= 50; $i++){
$dp[$i] = $dp[$i - 1] * 2 + 3;
$p[$i] = $p[$i - 1] * 2 + 1;
}
echo dfs($N, $X);
function dfs($N, $X){
global $dp, $p;
if($X >= $dp[$N])return $p[$N];
if($X <= 0)return 0;
if($N == 0)return 1;
$sum = dfs($N - 1, $X - 1);
if($X >= $dp[$N - 1] + 2)$sum++;
$sum += dfs($N - 1, $X - 1 - $dp[$N-1] - 1);
return $sum;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02658 | PHP | Accepted | <?php
fscanf(STDIN, "%d", $n);
$list = explode(" ", trim(fgets(STDIN)));
$result = array_product($list);
if (in_array(0, $list)) {
echo 0;
} elseif ($result > pow(10, 18)) {
echo -1;
} else {
echo $result;
}
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d", $n);
$list = explode(" ", trim(fgets(STDIN)));
$result = array_product($list);
if (in_array(0, $list)) {
echo 0;
} elseif ($result > pow(10, 18)) {
echo -1;
} else {
echo $result;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02675 | PHP | Accepted | <?php
fscanf(STDIN,"%d", $n);
$r = $n % 10;
if($r == 3){
echo "bon";
} elseif(in_array($r,[0,1,6,8])){
echo "pon";
} else {
echo "hon";
}
?>
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d", $n);
$r = $n % 10;
if($r == 3){
echo "bon";
} elseif(in_array($r,[0,1,6,8])){
echo "pon";
} else {
echo "hon";
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03943 | PHP | Accepted | <?php
//終端まで繰り返す
while ( ! feof(STDIN) ) {
$line[] = trim(fgets(STDIN));
}
$abc = explode(" ", $line[0]);
rsort($abc);
if ($abc[0] == ($abc[1] + $abc[2])) {
echo "Yes";
} else {
echo "No";
}
| Here is a piece of code written in PHP:
<?php
//終端まで繰り返す
while ( ! feof(STDIN) ) {
$line[] = trim(fgets(STDIN));
}
$abc = explode(" ", $line[0]);
rsort($abc);
if ($abc[0] == ($abc[1] + $abc[2])) {
echo "Yes";
} else {
echo "No";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02999 | PHP | Accepted | <?php
$line = trim(fgets(STDIN));
$lines = explode(' ', $line);
echo $lines[0] < $lines[1] ? 0 : 10;
?>
| Here is a piece of code written in PHP:
<?php
$line = trim(fgets(STDIN));
$lines = explode(' ', $line);
echo $lines[0] < $lines[1] ? 0 : 10;
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02707 | PHP | Accepted | <?php
fscanf(STDIN, "%d", $num);
$list = explode(" ", trim(fgets(STDIN)));
$map = array_fill(1,$num,0);
foreach($list as $value){
$map[$value]++;
}
echo implode(PHP_EOL,$map); | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d", $num);
$list = explode(" ", trim(fgets(STDIN)));
$map = array_fill(1,$num,0);
foreach($list as $value){
$map[$value]++;
}
echo implode(PHP_EOL,$map);
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03456 | PHP | Accepted | <?php
$a=join(explode(' ',fgets(STDIN)));
echo $a==floor($a**.5)**2?Yes:No; | Here is a piece of code written in PHP:
<?php
$a=join(explode(' ',fgets(STDIN)));
echo $a==floor($a**.5)**2?Yes:No;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03101 | PHP | Accepted | <?php
list($H,$W)=explode(" ",trim(fgets(STDIN)));
list($h,$w)=explode(" ",trim(fgets(STDIN)));
echo ($H-$h)*($W-$w); | Here is a piece of code written in PHP:
<?php
list($H,$W)=explode(" ",trim(fgets(STDIN)));
list($h,$w)=explode(" ",trim(fgets(STDIN)));
echo ($H-$h)*($W-$w);
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03086 | PHP | Accepted | <?php
$sString = readline();
$strList = ["A","T","C","G"];
$longestString = 0;
$strCtr = 0;
$len = strlen($sString);
for($x = 0; $x< $len; $x++){
if(in_array($sString[$x],$strList)){
$strCtr++;
} else {
$strCtr = 0;
}
if($strCtr > $longestString){$longestString = $strCtr;}
}
print $longestString; | Here is a piece of code written in PHP:
<?php
$sString = readline();
$strList = ["A","T","C","G"];
$longestString = 0;
$strCtr = 0;
$len = strlen($sString);
for($x = 0; $x< $len; $x++){
if(in_array($sString[$x],$strList)){
$strCtr++;
} else {
$strCtr = 0;
}
if($strCtr > $longestString){$longestString = $strCtr;}
}
print $longestString;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03574 | PHP | Accepted | <?php
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');
// define('DEBUG', true);
define('DEBUG', false);
$map = array(array());
fscanf(STDIN, "%d %d", $H, $W);
for ($i = 1; $i <= $H; $i++) {
fscanf(STDIN, "%s", $S);
$map[$i] = str_split(" " . $S);
}
// var_dump($map);
for ($i = 1; $i <= $H; $i++) {
for ($j = 1; $j <= $W; $j++) {
$x = 0;
if ($map[$i][$j] == ".") {
if ($map[$i-1][$j-1] == "#") {
$x++;
}
if ($map[$i-1][$j ] == "#") {
$x++;
}
if ($map[$i-1][$j+1] == "#") {
$x++;
}
if ($map[$i ][$j-1] == "#") {
$x++;
}
if ($map[$i ][$j+1] == "#") {
$x++;
}
if ($map[$i+1][$j-1] == "#") {
$x++;
}
if ($map[$i+1][$j ] == "#") {
$x++;
}
if ($map[$i+1][$j+1] == "#") {
$x++;
}
echo $x;
} else {
echo $map[$i][$j];
}
}
echo PHP_EOL;
} | Here is a piece of code written in PHP:
<?php
ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');
// define('DEBUG', true);
define('DEBUG', false);
$map = array(array());
fscanf(STDIN, "%d %d", $H, $W);
for ($i = 1; $i <= $H; $i++) {
fscanf(STDIN, "%s", $S);
$map[$i] = str_split(" " . $S);
}
// var_dump($map);
for ($i = 1; $i <= $H; $i++) {
for ($j = 1; $j <= $W; $j++) {
$x = 0;
if ($map[$i][$j] == ".") {
if ($map[$i-1][$j-1] == "#") {
$x++;
}
if ($map[$i-1][$j ] == "#") {
$x++;
}
if ($map[$i-1][$j+1] == "#") {
$x++;
}
if ($map[$i ][$j-1] == "#") {
$x++;
}
if ($map[$i ][$j+1] == "#") {
$x++;
}
if ($map[$i+1][$j-1] == "#") {
$x++;
}
if ($map[$i+1][$j ] == "#") {
$x++;
}
if ($map[$i+1][$j+1] == "#") {
$x++;
}
echo $x;
} else {
echo $map[$i][$j];
}
}
echo PHP_EOL;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03455 | PHP | Accepted | <?php
$input = explode(" ", fgets(STDIN));
$a = (integer)$input[0];
$b = (integer)$input[1];
if (($a*$b)%2==0){
print 'Even';
}else{
print 'Odd';
}
?> | Here is a piece of code written in PHP:
<?php
$input = explode(" ", fgets(STDIN));
$a = (integer)$input[0];
$b = (integer)$input[1];
if (($a*$b)%2==0){
print 'Even';
}else{
print 'Odd';
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03147 | PHP | Accepted | <?php
$n=trim(fgets(STDIN));
$h = explode(" ", trim(fgets(STDIN)));
$count = 0;
while(array_sum($h) < (101*$n)){
$min = min($h);
$flag = false;
for($j=0; $j<$n; $j++){
if($h[$j] >= $min && $h[$j] != 101){
$flag=true;
$h[$j] -= $min;
}else{
if($flag){
$count += $min;
}
$flag = false;
}
if($h[$j] == 0) $h[$j] = 101;
}
if($flag) $count+=$min;
}
echo $count; | Here is a piece of code written in PHP:
<?php
$n=trim(fgets(STDIN));
$h = explode(" ", trim(fgets(STDIN)));
$count = 0;
while(array_sum($h) < (101*$n)){
$min = min($h);
$flag = false;
for($j=0; $j<$n; $j++){
if($h[$j] >= $min && $h[$j] != 101){
$flag=true;
$h[$j] -= $min;
}else{
if($flag){
$count += $min;
}
$flag = false;
}
if($h[$j] == 0) $h[$j] = 101;
}
if($flag) $count+=$min;
}
echo $count;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02399 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d", $a, $b);
$f = round($a / $b, 5);
$r = $a % $b;
$d = floor($f);
echo $d." ".$r." ".$f."\n";
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d", $a, $b);
$f = round($a / $b, 5);
$r = $a % $b;
$d = floor($f);
echo $d." ".$r." ".$f."\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03455 | PHP | Accepted | <?php
class Scanner {
private $arr = [];
private $count = 0;
private $pointer = 0;
public function next() {
if($this->pointer >= $this->count) {
$str = trim(fgets(STDIN));
$this->arr = explode(' ', $str);
$this->count = count($this->arr);
$this->pointer = 0;
}
$result = $this->arr[$this->pointer];
$this->pointer++;
return $result;
}
public function hasNext() {
return $this->pointer < $this->count;
}
public function nextInt() {
return (int)$this->next();
}
public function nextDouble() {
return (double)$this->next();
}
}
class out {
public static function println($str = "") {
echo $str . PHP_EOL;
}
}
$sc = new Scanner;
$b = $sc->nextInt();
$c = $sc->nextInt();
$d = $b * $c;
if ($d % 2 == 0) {
out::println('Even');
} else {
out::println('Odd');
}
?>
| Here is a piece of code written in PHP:
<?php
class Scanner {
private $arr = [];
private $count = 0;
private $pointer = 0;
public function next() {
if($this->pointer >= $this->count) {
$str = trim(fgets(STDIN));
$this->arr = explode(' ', $str);
$this->count = count($this->arr);
$this->pointer = 0;
}
$result = $this->arr[$this->pointer];
$this->pointer++;
return $result;
}
public function hasNext() {
return $this->pointer < $this->count;
}
public function nextInt() {
return (int)$this->next();
}
public function nextDouble() {
return (double)$this->next();
}
}
class out {
public static function println($str = "") {
echo $str . PHP_EOL;
}
}
$sc = new Scanner;
$b = $sc->nextInt();
$c = $sc->nextInt();
$d = $b * $c;
if ($d % 2 == 0) {
out::println('Even');
} else {
out::println('Odd');
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03323 | PHP | Accepted | <?php
fscanf(STDIN,"%d %d",$a,$b);
echo $a<9&&$b<9?"Yay!":":("; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d %d",$a,$b);
echo $a<9&&$b<9?"Yay!":":(";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02754 | PHP | Accepted | <?php
// Your code here!
// $s = trim(fgets(STDIN));
fscanf(STDIN, "%d %d %d", $n,$a,$b);
$sum = $a + $b;
$syou = intval($n / $sum);
$amari = $n % $sum;
$ans = $syou * $a;
if($amari > 0){
$ans += (min($amari, $a));
}
echo $ans;
?> | Here is a piece of code written in PHP:
<?php
// Your code here!
// $s = trim(fgets(STDIN));
fscanf(STDIN, "%d %d %d", $n,$a,$b);
$sum = $a + $b;
$syou = intval($n / $sum);
$amari = $n % $sum;
$ans = $syou * $a;
if($amari > 0){
$ans += (min($amari, $a));
}
echo $ans;
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03206 | PHP | Accepted | <?php
$s = trim(fgets(STDIN));
echo 'Christmas';
for($i=0; $i<25-$s; $i++){
echo ' '.'Eve';
}
?> | Here is a piece of code written in PHP:
<?php
$s = trim(fgets(STDIN));
echo 'Christmas';
for($i=0; $i<25-$s; $i++){
echo ' '.'Eve';
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03061 | PHP | Accepted | <?php
//学習用 / 自作コードではありません
$n = trim(fgets(STDIN));
$list = explode(" ", trim(fgets(STDIN)));
if($n == 2){
echo max($list);
exit;
}
$left[0] = $list[0];
for($i=1;$i<$n;$i++){
$left[$i]=gcd($left[$i-1], $list[$i]);
}
$right[$n-1] = $list[$n-1];
for($i=$n-2;$i>=0;$i--){
$right[$i]=gcd($right[$i+1], $list[$i]);
}
$ans = max($right[1], $left[$n-2]);
for($i=0;$i<$n-2;$i++){
$ans = max($ans, gcd($left[$i], $right[$i+2]));
}
echo $ans;
function gcd($m, $n){
if($n > $m) list($m, $n) = array($n, $m);
while($n !== 0){
$tmp_n = $n;
$n = $m % $n;
$m = $tmp_n;
}
return $m;
} | Here is a piece of code written in PHP:
<?php
//学習用 / 自作コードではありません
$n = trim(fgets(STDIN));
$list = explode(" ", trim(fgets(STDIN)));
if($n == 2){
echo max($list);
exit;
}
$left[0] = $list[0];
for($i=1;$i<$n;$i++){
$left[$i]=gcd($left[$i-1], $list[$i]);
}
$right[$n-1] = $list[$n-1];
for($i=$n-2;$i>=0;$i--){
$right[$i]=gcd($right[$i+1], $list[$i]);
}
$ans = max($right[1], $left[$n-2]);
for($i=0;$i<$n-2;$i++){
$ans = max($ans, gcd($left[$i], $right[$i+2]));
}
echo $ans;
function gcd($m, $n){
if($n > $m) list($m, $n) = array($n, $m);
while($n !== 0){
$tmp_n = $n;
$n = $m % $n;
$m = $tmp_n;
}
return $m;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03424 | PHP | Accepted | <?php
$n=trim(fgets(STDIN));
$a=explode(' ',fgets(STDIN));
while($n>0){
--$n;
if($a[$n]=='Y'){
echo 'Four';
exit;
}
}
echo 'Three'; | Here is a piece of code written in PHP:
<?php
$n=trim(fgets(STDIN));
$a=explode(' ',fgets(STDIN));
while($n>0){
--$n;
if($a[$n]=='Y'){
echo 'Four';
exit;
}
}
echo 'Three';
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p00000 | PHP | Accepted | <?php
//?????????????????????for???
for($i=1;$i<=9;$i++){
//??£????????§??°????????????????????????for???
for($j=1;$j<=9;$j++){
//???????????????
echo $i."x".$j."=".$i*$j."\n";
}
} | Here is a piece of code written in PHP:
<?php
//?????????????????????for???
for($i=1;$i<=9;$i++){
//??£????????§??°????????????????????????for???
for($j=1;$j<=9;$j++){
//???????????????
echo $i."x".$j."=".$i*$j."\n";
}
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03238 | PHP | Accepted | <?php
fscanf(STDIN,"%d",$n);
if($n==1){
echo 'Hello World';
}
elseif($n==2){
fscanf(STDIN,"%d",$a);
fscanf(STDIN,"%d",$b);
$ans=$a+$b;
echo $ans;
}
?> | Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d",$n);
if($n==1){
echo 'Hello World';
}
elseif($n==2){
fscanf(STDIN,"%d",$a);
fscanf(STDIN,"%d",$b);
$ans=$a+$b;
echo $ans;
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02546 | PHP | Accepted | <?php
//$S = (int)trim(fgets(STDIN));
$S = trim(fgets(STDIN));
//list($a,$b,$c,$d) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
$l = substr($S,-1);
if ($l=='s') {
echo $S."es";
}
else {
echo $S."s";
}
| Here is a piece of code written in PHP:
<?php
//$S = (int)trim(fgets(STDIN));
$S = trim(fgets(STDIN));
//list($a,$b,$c,$d) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
$l = substr($S,-1);
if ($l=='s') {
echo $S."es";
}
else {
echo $S."s";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p04031 | PHP | Accepted | <?php
fscanf(STDIN, "%d", $n);
$line = fgets(STDIN);
$lines = explode(" ", $line);
$ave = round(array_sum($lines)/count($lines));
$cost = 0;
for ($i = 0; $i < $n; $i++) {
$cost += ($lines[$i]-$ave)**2;
}
echo $cost;
?> | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d", $n);
$line = fgets(STDIN);
$lines = explode(" ", $line);
$ave = round(array_sum($lines)/count($lines));
$cost = 0;
for ($i = 0; $i < $n; $i++) {
$cost += ($lines[$i]-$ave)**2;
}
echo $cost;
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02754 | PHP | Accepted | <?php
fscanf(STDIN, '%d %d %d', $n, $a, $b);
$sum = $a + $b;
$fraction = $n % $sum;
if ($n >= $sum) {
$count = (int)floor($n / $sum);
$result = $count * $a;
} else {
$result = 0;
}
if ($a >= $fraction) {
$result += $fraction;
} else {
$result += $a;
}
echo $result; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, '%d %d %d', $n, $a, $b);
$sum = $a + $b;
$fraction = $n % $sum;
if ($n >= $sum) {
$count = (int)floor($n / $sum);
$result = $count * $a;
} else {
$result = 0;
}
if ($a >= $fraction) {
$result += $fraction;
} else {
$result += $a;
}
echo $result;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03210 | PHP | Accepted | <?php
echo in_array(trim(fgets(STDIN)), [7,5,3]) ? 'YES' : 'NO'; | Here is a piece of code written in PHP:
<?php
echo in_array(trim(fgets(STDIN)), [7,5,3]) ? 'YES' : 'NO';
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02570 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d %d", $d, $t, $s);
if($d/$s>$t){
echo "No";
}else{
echo "Yes";} | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d %d", $d, $t, $s);
if($d/$s>$t){
echo "No";
}else{
echo "Yes";}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03053 | PHP | Accepted | <?php
fscanf(STDIN, "%d%d", $H, $W);
for($y = 0; $y < $H; $y++){
fscanf(STDIN, "%s", $str);
$map[$y] = str_split($str);
for($x = 0; $x < $W; $x++){
if($map[$y][$x] == "#"){
$list[$y][$x] = 1;
}
}
}
$count = 0;
$HM = $H - 1;
$WM = $W - 1;
while($list){
$nextList = [];
foreach($list as $y => $xs)foreach($xs as $x => $_){
if($x && $map[$y][$x-1] == ".")$nextList[$y][$x-1] = $map[$y][$x-1] = 1;
if($y && $map[$y-1][$x] == ".")$nextList[$y-1][$x] = $map[$y-1][$x] = 1;
if($x < $WM && $map[$y][$x+1] == ".")$nextList[$y][$x+1] = $map[$y][$x+1] = 1;
if($y < $HM && $map[$y+1][$x] == ".")$nextList[$y+1][$x] = $map[$y+1][$x] = 1;
}
$list = $nextList;
if($list)$count++;
}
echo $count;
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($y = 0; $y < $H; $y++){
fscanf(STDIN, "%s", $str);
$map[$y] = str_split($str);
for($x = 0; $x < $W; $x++){
if($map[$y][$x] == "#"){
$list[$y][$x] = 1;
}
}
}
$count = 0;
$HM = $H - 1;
$WM = $W - 1;
while($list){
$nextList = [];
foreach($list as $y => $xs)foreach($xs as $x => $_){
if($x && $map[$y][$x-1] == ".")$nextList[$y][$x-1] = $map[$y][$x-1] = 1;
if($y && $map[$y-1][$x] == ".")$nextList[$y-1][$x] = $map[$y-1][$x] = 1;
if($x < $WM && $map[$y][$x+1] == ".")$nextList[$y][$x+1] = $map[$y][$x+1] = 1;
if($y < $HM && $map[$y+1][$x] == ".")$nextList[$y+1][$x] = $map[$y+1][$x] = 1;
}
$list = $nextList;
if($list)$count++;
}
echo $count;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03861 | PHP | Accepted | <?php
list($a,$b,$x) = explode(" ",trim(fgets(STDIN)));
$q = $b % $x;
if($a == $b){
echo $q == 0? 1:0;
}else{
$r = $a % $x;
$ans = ($b - $q - $a + $r) / $x;
echo $r == 0? $ans + 1:$ans;
} | Here is a piece of code written in PHP:
<?php
list($a,$b,$x) = explode(" ",trim(fgets(STDIN)));
$q = $b % $x;
if($a == $b){
echo $q == 0? 1:0;
}else{
$r = $a % $x;
$ans = ($b - $q - $a + $r) / $x;
echo $r == 0? $ans + 1:$ans;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03360 | PHP | Accepted | <?php
$input=explode(' ',trim(fgets(STDIN))); // // 1 2 3 ……
$k_num = trim(fgets(STDIN)); //数字や文字列
sort($input);
for ($i = 0; $i < $k_num; $i++) {
$input[2] = $input[2] * 2;
}
echo( array_sum($input) );
?> | Here is a piece of code written in PHP:
<?php
$input=explode(' ',trim(fgets(STDIN))); // // 1 2 3 ……
$k_num = trim(fgets(STDIN)); //数字や文字列
sort($input);
for ($i = 0; $i < $k_num; $i++) {
$input[2] = $input[2] * 2;
}
echo( array_sum($input) );
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03105 | PHP | Accepted | <?php
list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
if ($b / $a >= $c) {
echo $c, PHP_EOL;
} else {
echo floor($b / $a), PHP_EOL;
} | Here is a piece of code written in PHP:
<?php
list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
if ($b / $a >= $c) {
echo $c, PHP_EOL;
} else {
echo floor($b / $a), PHP_EOL;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02398 | PHP | Accepted | <?php
list($a,$b,$c)=explode(' ',trim(fgets(STDIN)));
$d=0;
for(;$a<=$b;$a++){if(0==$c%$a){++$d;}}
print $d;
?> | Here is a piece of code written in PHP:
<?php
list($a,$b,$c)=explode(' ',trim(fgets(STDIN)));
$d=0;
for(;$a<=$b;$a++){if(0==$c%$a){++$d;}}
print $d;
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02790 | PHP | Accepted | <?php
fscanf(STDIN, "%s %s", $a, $b);
$aa = str_repeat($a, $b);
$bb = str_repeat($b, $a);
echo strcmp($aa, $bb) < 0 ? $aa : $bb; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%s %s", $a, $b);
$aa = str_repeat($a, $b);
$bb = str_repeat($b, $a);
echo strcmp($aa, $bb) < 0 ? $aa : $bb;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02730 | PHP | Accepted | <?php
fscanf(STDIN, '%s', $S);
function judge(string $s):bool
{
return $s === strrev($s);
}
if (judge($S) && judge(substr($S, 0, (strlen($S) - 1) / 2)) && judge(substr($S, (strlen($S) + 3) /2 - 1))) {
echo "Yes";
} else {
echo "No";
}
echo PHP_EOL;
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, '%s', $S);
function judge(string $s):bool
{
return $s === strrev($s);
}
if (judge($S) && judge(substr($S, 0, (strlen($S) - 1) / 2)) && judge(substr($S, (strlen($S) + 3) /2 - 1))) {
echo "Yes";
} else {
echo "No";
}
echo PHP_EOL;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02401 | PHP | Accepted | <?php
while (true) {
list($a, $operator, $b) = getSpacesByExplodeTrimInput();
switch ($operator) {
case '+':
$result = addingTwoNum($a, $b);
break;
case '-':
$result = subTractTwoNum($a, $b);
break;
case '*':
$result = multiplyTwoNum($a, $b);
break;
case '/':
$result = divideTwoNumByFloorPoint($a, $b);
break;
case '?':
exit;
}
echo $result, PHP_EOL;
}
function getSpacesByExplodeTrimInput()
{
return explode(' ', trim(fgets(STDIN)));
}
function addingTwoNum($a, $b)
{
return $a + $b;
}
function subTractTwoNum($a, $b)
{
return $a - $b;
}
function multiplyTwoNum($a, $b)
{
return $a * $b;
}
function divideTwoNumByFloorPoint($a, $b)
{
return floor($a / $b);
} | Here is a piece of code written in PHP:
<?php
while (true) {
list($a, $operator, $b) = getSpacesByExplodeTrimInput();
switch ($operator) {
case '+':
$result = addingTwoNum($a, $b);
break;
case '-':
$result = subTractTwoNum($a, $b);
break;
case '*':
$result = multiplyTwoNum($a, $b);
break;
case '/':
$result = divideTwoNumByFloorPoint($a, $b);
break;
case '?':
exit;
}
echo $result, PHP_EOL;
}
function getSpacesByExplodeTrimInput()
{
return explode(' ', trim(fgets(STDIN)));
}
function addingTwoNum($a, $b)
{
return $a + $b;
}
function subTractTwoNum($a, $b)
{
return $a - $b;
}
function multiplyTwoNum($a, $b)
{
return $a * $b;
}
function divideTwoNumByFloorPoint($a, $b)
{
return floor($a / $b);
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03415 | PHP | Accepted | <?php
echo fgets(STDIN)[0];
echo fgets(STDIN)[1];
echo fgets(STDIN)[2];
| Here is a piece of code written in PHP:
<?php
echo fgets(STDIN)[0];
echo fgets(STDIN)[1];
echo fgets(STDIN)[2];
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02257 | PHP | Accepted | <?php
function input() {
return trim(fgets(STDIN));
}
function input_array() {
return explode(' ', input());
}
function isPrime($x) {
if ($x < 2) return false;
else if ($x === 2) return true;
else if ($x % 2 === 0) return false;
else {
for ($i = 3; $i ** 2 <= $x; $i++) {
if ($x % $i === 0) return false;
}
return true;
}
}
$count = 0;
$n = (int)input();
for ($i = 0; $i < $n; $i++) {
$x = (int)input();
if (isPrime($x)) $count++;
}
echo "{$count}\n";
| Here is a piece of code written in PHP:
<?php
function input() {
return trim(fgets(STDIN));
}
function input_array() {
return explode(' ', input());
}
function isPrime($x) {
if ($x < 2) return false;
else if ($x === 2) return true;
else if ($x % 2 === 0) return false;
else {
for ($i = 3; $i ** 2 <= $x; $i++) {
if ($x % $i === 0) return false;
}
return true;
}
}
$count = 0;
$n = (int)input();
for ($i = 0; $i < $n; $i++) {
$x = (int)input();
if (isPrime($x)) $count++;
}
echo "{$count}\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02394 | PHP | Accepted | <?php
$input =trim(fgets(STDIN));
$input=explode(" ",$input);
$w=$input[0];
$h=$input[1];
$x=$input[2];
$y=$input[3];
$r=$input[4];
if($x -$r < 0 || $w < $x+$r){
echo "No";
}
elseif($y -$r < 0 || $h < $y+$r){
echo "No";
}
else echo "Yes";
?> | Here is a piece of code written in PHP:
<?php
$input =trim(fgets(STDIN));
$input=explode(" ",$input);
$w=$input[0];
$h=$input[1];
$x=$input[2];
$y=$input[3];
$r=$input[4];
if($x -$r < 0 || $w < $x+$r){
echo "No";
}
elseif($y -$r < 0 || $h < $y+$r){
echo "No";
}
else echo "Yes";
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02647 | PHP | Accepted | <?php
list($n, $k) = array_map('intval', explode(" ", trim(fgets(STDIN))));
$a = array_map('intval', explode(" ", trim(fgets(STDIN))));
$loop = min($k, 50);
for ($h=0; $h<$loop; $h++) {
$x = array_fill(0, $n+1, 0);
for ($i=0; $i<$n; $i++) {
$l = max($i-$a[$i], 0);
$r = min($i+$a[$i]+1, $n);
$x[$l]++;
$x[$r]--;
}
$a[0]=$x[0];
for ($i=1; $i<$n; $i++) {
$a[$i]=$a[$i-1]+$x[$i];
}
}
echo implode(" ", $a); | Here is a piece of code written in PHP:
<?php
list($n, $k) = array_map('intval', explode(" ", trim(fgets(STDIN))));
$a = array_map('intval', explode(" ", trim(fgets(STDIN))));
$loop = min($k, 50);
for ($h=0; $h<$loop; $h++) {
$x = array_fill(0, $n+1, 0);
for ($i=0; $i<$n; $i++) {
$l = max($i-$a[$i], 0);
$r = min($i+$a[$i]+1, $n);
$x[$l]++;
$x[$r]--;
}
$a[0]=$x[0];
for ($i=1; $i<$n; $i++) {
$a[$i]=$a[$i-1]+$x[$i];
}
}
echo implode(" ", $a);
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02684 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d", $N, $K);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cursor = 1;
$line = ['1'];
$visited = ['1' => 1];
$next = null;
$ans = null;
while(true) {
$next = $A[$cursor - 1];
if (isset($visited[$next])) {
$pos = array_search($next, $line);
$K -= $pos;
$loop = count($line) - $pos;
$ans = $line[$pos + $K % $loop];
break;
} else {
$line[] = $next;
$visited[$next] = 1;
}
if (count($line) === $K + 1) {
$ans = $next;
break;
}
$cursor = $next;
}
printf("%d", $ans);
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d", $N, $K);
$A = array_map('intval', explode(' ', trim(fgets(STDIN))));
$cursor = 1;
$line = ['1'];
$visited = ['1' => 1];
$next = null;
$ans = null;
while(true) {
$next = $A[$cursor - 1];
if (isset($visited[$next])) {
$pos = array_search($next, $line);
$K -= $pos;
$loop = count($line) - $pos;
$ans = $line[$pos + $K % $loop];
break;
} else {
$line[] = $next;
$visited[$next] = 1;
}
if (count($line) === $K + 1) {
$ans = $next;
break;
}
$cursor = $next;
}
printf("%d", $ans);
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02784 | PHP | Accepted | <?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$h = (int)$input[0];
$n = (int)$input[1];
$sum = 0;
$input = explode(' ', trim(fgets(STDIN)));
foreach ($input as $a) {
$sum += (int)$a;
}
if ($h <= $sum) {
echo 'Yes';
}else{
echo 'No';
} | Here is a piece of code written in PHP:
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));
$h = (int)$input[0];
$n = (int)$input[1];
$sum = 0;
$input = explode(' ', trim(fgets(STDIN)));
foreach ($input as $a) {
$sum += (int)$a;
}
if ($h <= $sum) {
echo 'Yes';
}else{
echo 'No';
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p00004 | PHP | Accepted | <?php
//ガウスジョルダン法
$count = 2; //未知数の数
$value = array(); //係数配列
while(1){
$res =fscanf(STDIN, '%d %d %d %d %d %d', $a,$b,$c,$d,$e,$f);
if ($res==0) break;
$value[0][0]=$a; $value[0][1]=$b; $value[0][2]=$c;
$value[1][0]=$d; $value[1][1]=$e; $value[1][2]=$f;
// $a or $e が0だと処理が止まるので入れ替えておく
if ($a===0 && $e===0){
//両方とも0なら計算する必要なし
$y = $c/$b; $x = $f/$d;
$x = round($x, 3); $y = round($y, 3);
$x = sprintf('%.3f', $x); $y = sprintf('%.3f', $y);
echo $x.' '.$y.PHP_EOL;
continue;
} else if ($a===0 || $e===0) {
$value[0][0]=$d; $value[0][1]=$e; $value[0][2]=$f;
$value[1][0]=$a; $value[1][1]=$b; $value[1][2]=$c;
}
for($i=0; $i<$count; ++$i){
//注目式の未知数の係数を1にするためにその係数を格納
$a = $value[$i][$i];
//注目式の未知数の係数を1にするために注目式全体をaで割る
for($j=$i; $j<=$count; ++$j){
$value[$i][$j] = $value[$i][$j]/$a;
}
//注目式以外の未知数の係数を0にする
for($j=0; $j<$count; ++$j){
//注目式ならばスルー
if ($j===$i) continue;
//注目式以外の未知数の係数を格納
$tmp = $value[$j][$i];
//その値を0にするため、注目式との演算を行う
for($k=0; $k<=$count; ++$k){
//$value[$i][$k] が注目式の該当未知数の係数
$value[$j][$k] = $value[$j][$k] - $tmp*$value[$i][$k];
}
}
}
//計算結果
$x = $value[0][2]; $y = $value[1][2];
$x = round($x, 3); $y = round($y, 3);
$x = sprintf('%.3f', $x); $y = sprintf('%.3f', $y);
echo $x.' '.$y.PHP_EOL;
} | Here is a piece of code written in PHP:
<?php
//ガウスジョルダン法
$count = 2; //未知数の数
$value = array(); //係数配列
while(1){
$res =fscanf(STDIN, '%d %d %d %d %d %d', $a,$b,$c,$d,$e,$f);
if ($res==0) break;
$value[0][0]=$a; $value[0][1]=$b; $value[0][2]=$c;
$value[1][0]=$d; $value[1][1]=$e; $value[1][2]=$f;
// $a or $e が0だと処理が止まるので入れ替えておく
if ($a===0 && $e===0){
//両方とも0なら計算する必要なし
$y = $c/$b; $x = $f/$d;
$x = round($x, 3); $y = round($y, 3);
$x = sprintf('%.3f', $x); $y = sprintf('%.3f', $y);
echo $x.' '.$y.PHP_EOL;
continue;
} else if ($a===0 || $e===0) {
$value[0][0]=$d; $value[0][1]=$e; $value[0][2]=$f;
$value[1][0]=$a; $value[1][1]=$b; $value[1][2]=$c;
}
for($i=0; $i<$count; ++$i){
//注目式の未知数の係数を1にするためにその係数を格納
$a = $value[$i][$i];
//注目式の未知数の係数を1にするために注目式全体をaで割る
for($j=$i; $j<=$count; ++$j){
$value[$i][$j] = $value[$i][$j]/$a;
}
//注目式以外の未知数の係数を0にする
for($j=0; $j<$count; ++$j){
//注目式ならばスルー
if ($j===$i) continue;
//注目式以外の未知数の係数を格納
$tmp = $value[$j][$i];
//その値を0にするため、注目式との演算を行う
for($k=0; $k<=$count; ++$k){
//$value[$i][$k] が注目式の該当未知数の係数
$value[$j][$k] = $value[$j][$k] - $tmp*$value[$i][$k];
}
}
}
//計算結果
$x = $value[0][2]; $y = $value[1][2];
$x = round($x, 3); $y = round($y, 3);
$x = sprintf('%.3f', $x); $y = sprintf('%.3f', $y);
echo $x.' '.$y.PHP_EOL;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03485 | PHP | Accepted | <?php
fscanf(STDIN,"%d%d",$a,$b);
print(($a+$b+1)>>1); | Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d%d",$a,$b);
print(($a+$b+1)>>1);
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02402 | PHP | Accepted | <?php
$valuetNum = trim(fgets(STDIN));
$values = getSpacesByExplodeInput();
printf("%d %d %d%s", min($values), max($values), array_sum($values), PHP_EOL);
function getSpacesByExplodeInput()
{
return explode(' ', trim(fgets(STDIN)));
} | Here is a piece of code written in PHP:
<?php
$valuetNum = trim(fgets(STDIN));
$values = getSpacesByExplodeInput();
printf("%d %d %d%s", min($values), max($values), array_sum($values), PHP_EOL);
function getSpacesByExplodeInput()
{
return explode(' ', trim(fgets(STDIN)));
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02261 | PHP | Accepted | <?php
fscanf(STDIN, '%d', $N);
$num_arr = explode(" ", trim(fgets(STDIN)));
$bubble_arr = bubble_sort($num_arr);
echo implode(" ", $bubble_arr)."\n";
is_stable($bubble_arr, $bubble_arr);
$selection_arr = selection_sort($num_arr);
echo implode(" ", $selection_arr)."\n";
is_stable($bubble_arr, $selection_arr);
function bubble_sort($num_arr) {
for ($i = 0, $len = count($num_arr); $i < $len; $i++) {
for ($j = $len - 1; $j > $i; $j--) {
$tmp = $j;
if ($num_arr[$j-1][1] > $num_arr[$tmp][1]) {
$card = $num_arr[$tmp];
$num_arr[$j] = $num_arr[$j-1];
$num_arr[$j - 1] = $card;
}
}
}
return $num_arr;
}
function selection_sort($num_arr){
$min = 0;
$flag = 0;
for ($i = 0; $i < count($num_arr)-1; $i++) {
$min = $i;
for ($j = $i+1; $j < count($num_arr); $j++) {
if ($num_arr[$j][1] < $num_arr[$min][1]) {
$min = $j;
$flag = 1;
}
}
if ($flag) {
$tmp = $num_arr[$i];
$num_arr[$i] = $num_arr[$min];
$num_arr[$min] = $tmp;
$flag = 0;
}
}
return $num_arr;
}
function is_stable($origin, $sort_arr) {
for ($i = 0; $i < count($origin); $i++) {
if ($origin[$i][0] != $sort_arr[$i][0]) {
echo "Not stable\n";
return;
}
}
echo "Stable\n";
}
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, '%d', $N);
$num_arr = explode(" ", trim(fgets(STDIN)));
$bubble_arr = bubble_sort($num_arr);
echo implode(" ", $bubble_arr)."\n";
is_stable($bubble_arr, $bubble_arr);
$selection_arr = selection_sort($num_arr);
echo implode(" ", $selection_arr)."\n";
is_stable($bubble_arr, $selection_arr);
function bubble_sort($num_arr) {
for ($i = 0, $len = count($num_arr); $i < $len; $i++) {
for ($j = $len - 1; $j > $i; $j--) {
$tmp = $j;
if ($num_arr[$j-1][1] > $num_arr[$tmp][1]) {
$card = $num_arr[$tmp];
$num_arr[$j] = $num_arr[$j-1];
$num_arr[$j - 1] = $card;
}
}
}
return $num_arr;
}
function selection_sort($num_arr){
$min = 0;
$flag = 0;
for ($i = 0; $i < count($num_arr)-1; $i++) {
$min = $i;
for ($j = $i+1; $j < count($num_arr); $j++) {
if ($num_arr[$j][1] < $num_arr[$min][1]) {
$min = $j;
$flag = 1;
}
}
if ($flag) {
$tmp = $num_arr[$i];
$num_arr[$i] = $num_arr[$min];
$num_arr[$min] = $tmp;
$flag = 0;
}
}
return $num_arr;
}
function is_stable($origin, $sort_arr) {
for ($i = 0; $i < count($origin); $i++) {
if ($origin[$i][0] != $sort_arr[$i][0]) {
echo "Not stable\n";
return;
}
}
echo "Stable\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03963 | PHP | Accepted | <?php
list($N,$K) = explode(" ",trim(fgets(STDIN)));
if($N == 1){
echo $K . PHP_EOL;
}else{
echo pow($K - 1,$N - 1) * $K . PHP_EOL;
}
?> | Here is a piece of code written in PHP:
<?php
list($N,$K) = explode(" ",trim(fgets(STDIN)));
if($N == 1){
echo $K . PHP_EOL;
}else{
echo pow($K - 1,$N - 1) * $K . PHP_EOL;
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02803 | PHP | Accepted | <?php
const INI_INF = 1001001001;
const MOVE_CROSS = [
[-1, 0], // 左
[ 0, -1], // 上
[ 1, 0], // 右
[ 0, 1], // 下
];
class Pair {
public $x;
public $y;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
}
# 入力
list($h, $w) = explode(' ', trim(fgets(STDIN)));
$maze = [];
for ($i=0; $i<$h; $i++) {
$maze[$i] = trim(fgets(STDIN));
}
$ans = 0;
for ($si=0; $si<$h; $si++) {
for ($sj=0; $sj<$w; $sj++) {
if ($maze[$si][$sj] == '#') { continue; }
$queue = [];
$dist = array_fill(0, $h, array_fill(0, $w, INI_INF));
$updateFunc = function($di, $dj, $d) use($maze, &$dist, &$queue) {
if ($dist[$di][$dj] != INI_INF) { return; }
$dist[$di][$dj] = $d;
array_push($queue, new Pair($di, $dj));
};
$updateFunc($si, $sj, 0);
while (!empty($queue)) {
//echo json_encode($queue)."\n";
$cell = array_shift($queue);
foreach (MOVE_CROSS as list($dx, $dy)) {
$nx = $cell->x + $dx;
$ny = $cell->y + $dy;
//echo sprintf("move to %d, %d, %s \n",$nx, $ny, json_encode($maze[$nx][$ny]));
if ( !isset($maze[$nx][$ny]) ) { continue; }
if ($maze[$nx][$ny] == '#') { continue; }
$updateFunc($nx, $ny, $dist[$cell->x][$cell->y]+1);
}
}
// foreach ($dist as $distt) {
// echo implode(',', $distt)."\n";
// }
// echo "\n";
for ($i=0; $i<$h; $i++) {
for ($j=0; $j<$w; $j++) {
if ( $dist[$i][$j] == INI_INF) { continue; }
$ans = max($dist[$i][$j], $ans);
}
}
}
}
echo "$ans\n"; | Here is a piece of code written in PHP:
<?php
const INI_INF = 1001001001;
const MOVE_CROSS = [
[-1, 0], // 左
[ 0, -1], // 上
[ 1, 0], // 右
[ 0, 1], // 下
];
class Pair {
public $x;
public $y;
function __construct($x, $y) {
$this->x = $x;
$this->y = $y;
}
}
# 入力
list($h, $w) = explode(' ', trim(fgets(STDIN)));
$maze = [];
for ($i=0; $i<$h; $i++) {
$maze[$i] = trim(fgets(STDIN));
}
$ans = 0;
for ($si=0; $si<$h; $si++) {
for ($sj=0; $sj<$w; $sj++) {
if ($maze[$si][$sj] == '#') { continue; }
$queue = [];
$dist = array_fill(0, $h, array_fill(0, $w, INI_INF));
$updateFunc = function($di, $dj, $d) use($maze, &$dist, &$queue) {
if ($dist[$di][$dj] != INI_INF) { return; }
$dist[$di][$dj] = $d;
array_push($queue, new Pair($di, $dj));
};
$updateFunc($si, $sj, 0);
while (!empty($queue)) {
//echo json_encode($queue)."\n";
$cell = array_shift($queue);
foreach (MOVE_CROSS as list($dx, $dy)) {
$nx = $cell->x + $dx;
$ny = $cell->y + $dy;
//echo sprintf("move to %d, %d, %s \n",$nx, $ny, json_encode($maze[$nx][$ny]));
if ( !isset($maze[$nx][$ny]) ) { continue; }
if ($maze[$nx][$ny] == '#') { continue; }
$updateFunc($nx, $ny, $dist[$cell->x][$cell->y]+1);
}
}
// foreach ($dist as $distt) {
// echo implode(',', $distt)."\n";
// }
// echo "\n";
for ($i=0; $i<$h; $i++) {
for ($j=0; $j<$w; $j++) {
if ( $dist[$i][$j] == INI_INF) { continue; }
$ans = max($dist[$i][$j], $ans);
}
}
}
}
echo "$ans\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02921 | PHP | Accepted | <?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
if($S == "SSS"){
$aS = "S";
$bS = "S";
$cS = "S";
}else if($S == "SSC"){
$aS = "S";
$bS = "S";
$cS = "C";
}else if($S == "SSR"){
$aS = "S";
$bS = "S";
$cS = "R";
}else if($S == "SCS"){
$aS = "S";
$bS = "C";
$cS = "S";
}else if($S == "SRS"){
$aS = "S";
$bS = "R";
$cS = "S";
}else if($S == "CSS"){
$aS = "C";
$bS = "S";
$cS = "S";
}else if($S == "RSS"){
$aS = "R";
$bS = "S";
$cS = "S";
}else if($S == "SCC"){
$aS = "S";
$bS = "C";
$cS = "C";
}else if($S == "SCR"){
$aS = "S";
$bS = "C";
$cS = "R";
}else if($S == "SRC"){
$aS = "S";
$bS = "R";
$cS = "C";
}else if($S == "SRR"){
$aS = "S";
$bS = "R";
$cS = "R";
}else if($S == "CSC"){
$aS = "C";
$bS = "S";
$cS = "C";
}else if($S == "CSR"){
$aS = "C";
$bS = "S";
$cS = "R";
}else if($S == "RSC"){
$aS = "R";
$bS = "S";
$cS = "C";
}else if($S == "RSR"){
$aS = "R";
$bS = "S";
$cS = "R";
}else if($S == "CCS"){
$aS = "C";
$bS = "C";
$cS = "S";
}else if($S == "CRS"){
$aS = "C";
$bS = "R";
$cS = "S";
}else if($S == "RCS"){
$aS = "R";
$bS = "C";
$cS = "S";
}else if($S == "RRS"){
$aS = "R";
$bS = "R";
$cS = "S";
}else if($S == "CCC"){
$aS = "C";
$bS = "C";
$cS = "C";
}else if($S == "CCR"){
$aS = "C";
$bS = "C";
$cS = "R";
}else if($S == "CRC"){
$aS = "C";
$bS = "R";
$cS = "C";
}else if($S == "RCC"){
$aS = "R";
$bS = "C";
$cS = "C";
}else if($S == "CRR"){
$aS = "C";
$bS = "R";
$cS = "R";
}else if($S == "RCR"){
$aS = "R";
$bS = "C";
$cS = "R";
}else if($S == "RRC"){
$aS = "R";
$bS = "R";
$cS = "C";
}else if($S == "RRR"){
$aS = "R";
$bS = "R";
$cS = "R";
}
if($T == "SSS"){
$aT = "S";
$bT = "S";
$cT = "S";
}else if($T == "SSC"){
$aT = "S";
$bT = "S";
$cT = "C";
}else if($T == "SSR"){
$aT = "S";
$bT = "S";
$cT = "R";
}else if($T == "SCS"){
$aT = "S";
$bT = "C";
$cT = "S";
}else if($T == "SRS"){
$aT = "S";
$bT = "R";
$cT = "S";
}else if($T == "CSS"){
$aT = "C";
$bT = "S";
$cT = "S";
}else if($T == "RSS"){
$aT = "R";
$bT = "S";
$cT = "S";
}else if($T == "SCC"){
$aT = "S";
$bT = "C";
$cT = "C";
}else if($T == "SCR"){
$aT = "S";
$bT = "C";
$cT = "R";
}else if($T == "SRC"){
$aT = "S";
$bT = "R";
$cT = "C";
}else if($T == "SRR"){
$aT = "S";
$bT = "R";
$cT = "R";
}else if($T == "CSC"){
$aT = "C";
$bT = "S";
$cT = "C";
}else if($T == "CSR"){
$aT = "C";
$bT = "S";
$cT = "R";
}else if($T == "RSC"){
$aT = "R";
$bT = "S";
$cT = "C";
}else if($T == "RSR"){
$aT = "R";
$bT = "S";
$cT = "R";
}else if($T == "CCS"){
$aT = "C";
$bT = "C";
$cT = "S";
}else if($T == "CRS"){
$aT = "C";
$bT = "R";
$cT = "S";
}else if($T == "RCS"){
$aT = "R";
$bT = "C";
$cT = "S";
}else if($T == "RRS"){
$aT = "R";
$bT = "R";
$cT = "S";
}else if($T == "CCC"){
$aT = "C";
$bT = "C";
$cT = "C";
}else if($T == "CCR"){
$aT = "C";
$bT = "C";
$cT = "R";
}else if($T == "CRC"){
$aT = "C";
$bT = "R";
$cT = "C";
}else if($T == "RCC"){
$aT = "R";
$bT = "C";
$cT = "C";
}else if($T == "CRR"){
$aT = "C";
$bT = "R";
$cT = "R";
}else if($T == "RCR"){
$aT = "R";
$bT = "C";
$cT = "R";
}else if($T == "RRC"){
$aT = "R";
$bT = "R";
$cT = "C";
}else if($T == "RRR"){
$aT = "R";
$bT = "R";
$cT = "R";
}
$ans = 0;
if($aS == $aT){
$ans ++;
}
if($bS == $bT){
$ans ++;
}
if($cS == $cT){
$ans ++;
}
echo "$ans\n";
?> | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
if($S == "SSS"){
$aS = "S";
$bS = "S";
$cS = "S";
}else if($S == "SSC"){
$aS = "S";
$bS = "S";
$cS = "C";
}else if($S == "SSR"){
$aS = "S";
$bS = "S";
$cS = "R";
}else if($S == "SCS"){
$aS = "S";
$bS = "C";
$cS = "S";
}else if($S == "SRS"){
$aS = "S";
$bS = "R";
$cS = "S";
}else if($S == "CSS"){
$aS = "C";
$bS = "S";
$cS = "S";
}else if($S == "RSS"){
$aS = "R";
$bS = "S";
$cS = "S";
}else if($S == "SCC"){
$aS = "S";
$bS = "C";
$cS = "C";
}else if($S == "SCR"){
$aS = "S";
$bS = "C";
$cS = "R";
}else if($S == "SRC"){
$aS = "S";
$bS = "R";
$cS = "C";
}else if($S == "SRR"){
$aS = "S";
$bS = "R";
$cS = "R";
}else if($S == "CSC"){
$aS = "C";
$bS = "S";
$cS = "C";
}else if($S == "CSR"){
$aS = "C";
$bS = "S";
$cS = "R";
}else if($S == "RSC"){
$aS = "R";
$bS = "S";
$cS = "C";
}else if($S == "RSR"){
$aS = "R";
$bS = "S";
$cS = "R";
}else if($S == "CCS"){
$aS = "C";
$bS = "C";
$cS = "S";
}else if($S == "CRS"){
$aS = "C";
$bS = "R";
$cS = "S";
}else if($S == "RCS"){
$aS = "R";
$bS = "C";
$cS = "S";
}else if($S == "RRS"){
$aS = "R";
$bS = "R";
$cS = "S";
}else if($S == "CCC"){
$aS = "C";
$bS = "C";
$cS = "C";
}else if($S == "CCR"){
$aS = "C";
$bS = "C";
$cS = "R";
}else if($S == "CRC"){
$aS = "C";
$bS = "R";
$cS = "C";
}else if($S == "RCC"){
$aS = "R";
$bS = "C";
$cS = "C";
}else if($S == "CRR"){
$aS = "C";
$bS = "R";
$cS = "R";
}else if($S == "RCR"){
$aS = "R";
$bS = "C";
$cS = "R";
}else if($S == "RRC"){
$aS = "R";
$bS = "R";
$cS = "C";
}else if($S == "RRR"){
$aS = "R";
$bS = "R";
$cS = "R";
}
if($T == "SSS"){
$aT = "S";
$bT = "S";
$cT = "S";
}else if($T == "SSC"){
$aT = "S";
$bT = "S";
$cT = "C";
}else if($T == "SSR"){
$aT = "S";
$bT = "S";
$cT = "R";
}else if($T == "SCS"){
$aT = "S";
$bT = "C";
$cT = "S";
}else if($T == "SRS"){
$aT = "S";
$bT = "R";
$cT = "S";
}else if($T == "CSS"){
$aT = "C";
$bT = "S";
$cT = "S";
}else if($T == "RSS"){
$aT = "R";
$bT = "S";
$cT = "S";
}else if($T == "SCC"){
$aT = "S";
$bT = "C";
$cT = "C";
}else if($T == "SCR"){
$aT = "S";
$bT = "C";
$cT = "R";
}else if($T == "SRC"){
$aT = "S";
$bT = "R";
$cT = "C";
}else if($T == "SRR"){
$aT = "S";
$bT = "R";
$cT = "R";
}else if($T == "CSC"){
$aT = "C";
$bT = "S";
$cT = "C";
}else if($T == "CSR"){
$aT = "C";
$bT = "S";
$cT = "R";
}else if($T == "RSC"){
$aT = "R";
$bT = "S";
$cT = "C";
}else if($T == "RSR"){
$aT = "R";
$bT = "S";
$cT = "R";
}else if($T == "CCS"){
$aT = "C";
$bT = "C";
$cT = "S";
}else if($T == "CRS"){
$aT = "C";
$bT = "R";
$cT = "S";
}else if($T == "RCS"){
$aT = "R";
$bT = "C";
$cT = "S";
}else if($T == "RRS"){
$aT = "R";
$bT = "R";
$cT = "S";
}else if($T == "CCC"){
$aT = "C";
$bT = "C";
$cT = "C";
}else if($T == "CCR"){
$aT = "C";
$bT = "C";
$cT = "R";
}else if($T == "CRC"){
$aT = "C";
$bT = "R";
$cT = "C";
}else if($T == "RCC"){
$aT = "R";
$bT = "C";
$cT = "C";
}else if($T == "CRR"){
$aT = "C";
$bT = "R";
$cT = "R";
}else if($T == "RCR"){
$aT = "R";
$bT = "C";
$cT = "R";
}else if($T == "RRC"){
$aT = "R";
$bT = "R";
$cT = "C";
}else if($T == "RRR"){
$aT = "R";
$bT = "R";
$cT = "R";
}
$ans = 0;
if($aS == $aT){
$ans ++;
}
if($bS == $bT){
$ans ++;
}
if($cS == $cT){
$ans ++;
}
echo "$ans\n";
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02389 | PHP | Accepted | <?php
$input = fgets(STDIN);
list($a, $b) = explode(" ", $input);
$s = $a * $b;
$l = 2 * ($a + $b);
echo $s . " " . $l . "\n"; | Here is a piece of code written in PHP:
<?php
$input = fgets(STDIN);
list($a, $b) = explode(" ", $input);
$s = $a * $b;
$l = 2 * ($a + $b);
echo $s . " " . $l . "\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02887 | PHP | Accepted | <?php
$N = trim(fgets(STDIN));
$col = trim(fgets(STDIN));
$arr_col = str_split($col);
$count = count($arr_col);
for ($i = 0; $i < $count; $i++) {
if ($arr_col[$i] == $arr_col[$i+1]) {
$N --;
}
}
echo $N;
?> | Here is a piece of code written in PHP:
<?php
$N = trim(fgets(STDIN));
$col = trim(fgets(STDIN));
$arr_col = str_split($col);
$count = count($arr_col);
for ($i = 0; $i < $count; $i++) {
if ($arr_col[$i] == $arr_col[$i+1]) {
$N --;
}
}
echo $N;
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03999 | PHP | Accepted | <?php
//http://abc045.contest.atcoder.jp/tasks/arc061_a
fscanf(STDIN,"%d",$s);
$len = strlen($s);
$n = pow(2,$len-1);
$ans = 0;
for($i = 0 ; $i < $n ; ++$i){
//2進数0左詰め
//str_pad(decbin($i),$n,"0",STR_PAD_LEFT);
//sprintf("%'0".$len."b",$i);
$bin = array();
$bin = str_split(sprintf("%'0".$len."b",$i));
$formula = "";
for($j = 0; $j < $len ; ++$j ){
if(intval($bin[$j])===1){
$formula .= "+";
}
$formula .= strval($s)[$j];
}
$arrval = array();
$arrval = explode("+",$formula);
$ans += array_sum($arrval);
}
echo $ans,PHP_EOL; | Here is a piece of code written in PHP:
<?php
//http://abc045.contest.atcoder.jp/tasks/arc061_a
fscanf(STDIN,"%d",$s);
$len = strlen($s);
$n = pow(2,$len-1);
$ans = 0;
for($i = 0 ; $i < $n ; ++$i){
//2進数0左詰め
//str_pad(decbin($i),$n,"0",STR_PAD_LEFT);
//sprintf("%'0".$len."b",$i);
$bin = array();
$bin = str_split(sprintf("%'0".$len."b",$i));
$formula = "";
for($j = 0; $j < $len ; ++$j ){
if(intval($bin[$j])===1){
$formula .= "+";
}
$formula .= strval($s)[$j];
}
$arrval = array();
$arrval = explode("+",$formula);
$ans += array_sum($arrval);
}
echo $ans,PHP_EOL;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02402 | PHP | Accepted | <?php
$n = (int)trim(fgets(STDIN));
$ary = array();
$input = explode(" ", trim(fgets(STDIN)));
$min = min($input);
$max = max($input);
$sum = array_sum($input);
echo $min." ".$max." ".$sum.PHP_EOL;
| Here is a piece of code written in PHP:
<?php
$n = (int)trim(fgets(STDIN));
$ary = array();
$input = explode(" ", trim(fgets(STDIN)));
$min = min($input);
$max = max($input);
$sum = array_sum($input);
echo $min." ".$max." ".$sum.PHP_EOL;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02606 | PHP | Accepted | <?php
$count = 0;
$i = 0;
list($L,$R,$d) = sscanf(fgets(STDIN), "%d %d %d");
for($i = $L; $i <= $R; $i++){
if($i % $d == 0){
$count++;
}
}
echo $count;
?> | Here is a piece of code written in PHP:
<?php
$count = 0;
$i = 0;
list($L,$R,$d) = sscanf(fgets(STDIN), "%d %d %d");
for($i = $L; $i <= $R; $i++){
if($i % $d == 0){
$count++;
}
}
echo $count;
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03456 | PHP | Accepted | <?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $a, $b);
$str = sprintf("%s%s",$a,$b);
$sqrt = sqrt($str);
if( $sqrt == intval($sqrt) ){
echo 'Yes'."\n";
}else{
echo 'No'."\n";
}
| Here is a piece of code written in PHP:
<?php
# スペース区切りの整数の入力
fscanf(STDIN, "%d %d", $a, $b);
$str = sprintf("%s%s",$a,$b);
$sqrt = sqrt($str);
if( $sqrt == intval($sqrt) ){
echo 'Yes'."\n";
}else{
echo 'No'."\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02390 | PHP | Accepted | <?php
$hms = new HMSConverter(fgets(STDIN));
echo sprintf('%d:%d:%d', $hms->h(), $hms->m(), $hms->s()), PHP_EOL;
class HMSConverter
{
protected $second;
public function __construct($second)
{
$this->second = (int) $second;
}
public function h()
{
return floor($this->second / 60 / 60);
}
public function m()
{
return floor($this->second / 60) % 60;
}
public function s()
{
return $this->second % 60;
}
} | Here is a piece of code written in PHP:
<?php
$hms = new HMSConverter(fgets(STDIN));
echo sprintf('%d:%d:%d', $hms->h(), $hms->m(), $hms->s()), PHP_EOL;
class HMSConverter
{
protected $second;
public function __construct($second)
{
$this->second = (int) $second;
}
public function h()
{
return floor($this->second / 60 / 60);
}
public function m()
{
return floor($this->second / 60) % 60;
}
public function s()
{
return $this->second % 60;
}
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02775 | PHP | Accepted | <?php
$str = "0".trim(fgets(STDIN));
$l = strlen($str);
$dp0 = array_fill(0, $l+1, 0);//超えてないやつ
$dp1 = array_fill(0, $l+1, 0);//超えたやつ
for($i = 0; $i < $l; $i++){
$dp0[$i+1] = min($dp0[$i]+$str[$i], $dp1[$i]+10-$str[$i]);
$dp1[$i+1] = min($dp0[$i]+$str[$i]+1, $dp1[$i] + 9 - $str[$i]);
}
echo $dp0[$i],"\n";
| Here is a piece of code written in PHP:
<?php
$str = "0".trim(fgets(STDIN));
$l = strlen($str);
$dp0 = array_fill(0, $l+1, 0);//超えてないやつ
$dp1 = array_fill(0, $l+1, 0);//超えたやつ
for($i = 0; $i < $l; $i++){
$dp0[$i+1] = min($dp0[$i]+$str[$i], $dp1[$i]+10-$str[$i]);
$dp1[$i+1] = min($dp0[$i]+$str[$i]+1, $dp1[$i] + 9 - $str[$i]);
}
echo $dp0[$i],"\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02791 | PHP | Accepted | <?php
fscanf(STDIN, "%d", $n);
$array = explode(' ', trim(fgets(STDIN)));
$dummy = array();
$count = 0;
$min = null;
for ($i=0; $i < $n; $i++) {
if ($min == null || $min > $array[$i]) {
$min = $array[$i];
}
if ($array[$i] <= $min) {
$count++;
}
}
echo $count;
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d", $n);
$array = explode(' ', trim(fgets(STDIN)));
$dummy = array();
$count = 0;
$min = null;
for ($i=0; $i < $n; $i++) {
if ($min == null || $min > $array[$i]) {
$min = $array[$i];
}
if ($array[$i] <= $min) {
$count++;
}
}
echo $count;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02753 | PHP | Accepted | <?php
$input_array = str_split(trim(fgets(STDIN)));
if ($input_array[0] === $input_array[1]
&& $input_array[1] === $input_array[2]) {
echo "No";
} else {
echo "Yes";
}
| Here is a piece of code written in PHP:
<?php
$input_array = str_split(trim(fgets(STDIN)));
if ($input_array[0] === $input_array[1]
&& $input_array[1] === $input_array[2]) {
echo "No";
} else {
echo "Yes";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03826 | PHP | Accepted | <?php
$inputs = explode(' ', trim(fgets(STDIN)));
if($inputs[0] * $inputs[1] < $inputs[2] * $inputs[3]) echo $inputs[2] * $inputs[3];
else echo $inputs[0] * $inputs[1];
?> | Here is a piece of code written in PHP:
<?php
$inputs = explode(' ', trim(fgets(STDIN)));
if($inputs[0] * $inputs[1] < $inputs[2] * $inputs[3]) echo $inputs[2] * $inputs[3];
else echo $inputs[0] * $inputs[1];
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02392 | PHP | Accepted | <?php
fscanf(STDIN,"%d%d%d",$a,$b,$c);
if ($a < $b && $b < $c) {
print("Yes\n");
} else {
print("No\n");
} | Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d%d%d",$a,$b,$c);
if ($a < $b && $b < $c) {
print("Yes\n");
} else {
print("No\n");
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03000 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d", $N, $X);
$L = array_merge([0], explode(" ", trim(fgets(STDIN))));
array_map(function ($a) use (&$t, &$ans, $X) { $t += $a; $ans += ($t <= $X); }, $L);
echo $ans;
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d", $N, $X);
$L = array_merge([0], explode(" ", trim(fgets(STDIN))));
array_map(function ($a) use (&$t, &$ans, $X) { $t += $a; $ans += ($t <= $X); }, $L);
echo $ans;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02848 | PHP | Accepted | <?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$chars = str_split($s);
$base = ord('A');
foreach ($chars as $c) {
$index = ord($c) - $base;
echo chr($base + ($index + $n) % 26);
}
echo "\n";
?> | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d", $n);
fscanf(STDIN, "%s", $s);
$chars = str_split($s);
$base = ord('A');
foreach ($chars as $c) {
$index = ord($c) - $base;
echo chr($base + ($index + $n) % 26);
}
echo "\n";
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02759 | PHP | Accepted | <?php
$n = int();
echo ceil($n/2);
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;
}
| Here is a piece of code written in PHP:
<?php
$n = int();
echo ceil($n/2);
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;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p04044 | PHP | Accepted | <?php
fscanf(STDIN,"%d %d", $n,$l);
for ($i = 0; $i < $n; $i ++) {
$s[] = trim(fgets(STDIN));
}
sort($s);
echo implode($s);
?>
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d %d", $n,$l);
for ($i = 0; $i < $n; $i ++) {
$s[] = trim(fgets(STDIN));
}
sort($s);
echo implode($s);
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03324 | PHP | Accepted | <?php
fscanf(STDIN,"%d %d", $d, $n);
switch ($d) {
case '0':
if($n == 100) {
echo "101\n";
} else {
echo "$n\n";
}
break;
case '1':
if($n == 100) {
echo "10100\n";
} else {
$ans = $n * 100;
echo "$ans\n";
}
break;
default:
if($n == 100) {
echo "1010000\n";
} else {
$ans = $n * 10000;
echo "$ans\n";
}
break;
}
?>
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d %d", $d, $n);
switch ($d) {
case '0':
if($n == 100) {
echo "101\n";
} else {
echo "$n\n";
}
break;
case '1':
if($n == 100) {
echo "10100\n";
} else {
$ans = $n * 100;
echo "$ans\n";
}
break;
default:
if($n == 100) {
echo "1010000\n";
} else {
$ans = $n * 10000;
echo "$ans\n";
}
break;
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02798 | PHP | Accepted | <?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
$dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
$dp[0][0] = 0;
for($bit = 0, $NN = 1<<$N; $bit < $NN; ++$bit){
$con = 0;
$x = $bit;
$x = $x - (($x >> 1) & 0x55555555);
$x = ($x & 0x33333333) + (($x >> 2) & 0x33333333);
$x = ($x + ($x >> 4)) & 0x0f0f0f0f;
$x = $x + ($x >> 8);
$x = $x + ($x >> 16);
$con = $x & 0x0000003F;
$ords = [];
$iter = $con - 1;
for($i = 0; $i < $N; ++$i)
if(!($bit & (1<<$i)))
$ords[$i] = ++$iter;
for($s = 0; $s <= 50; ++$s){
if($dp[$bit][$s] == PHP_INT_MAX)continue;
foreach($ords as $p0 => $p1){
$ns = ($p0-$con) & 1 ? $B[$p0] : $A[$p0];
if($ns >= $s){
$nb = $bit | (1<<$p0);
$dp[$nb][$ns] = min($dp[$nb][$ns], $dp[$bit][$s] + abs($p1 - $con));
}
}
}
}
$min = min($dp[(1<<$N)-1]);
if($min == PHP_INT_MAX){
echo -1;
}else{
echo $min;
}
| Here is a piece of code written in PHP:
<?php
$N = intval(trim(fgets(STDIN)));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));
$B = array_map("intval", explode(" ", trim(fgets(STDIN))));
$dp = array_fill(0, 1<<$N, array_fill(0,51,PHP_INT_MAX));
$dp[0][0] = 0;
for($bit = 0, $NN = 1<<$N; $bit < $NN; ++$bit){
$con = 0;
$x = $bit;
$x = $x - (($x >> 1) & 0x55555555);
$x = ($x & 0x33333333) + (($x >> 2) & 0x33333333);
$x = ($x + ($x >> 4)) & 0x0f0f0f0f;
$x = $x + ($x >> 8);
$x = $x + ($x >> 16);
$con = $x & 0x0000003F;
$ords = [];
$iter = $con - 1;
for($i = 0; $i < $N; ++$i)
if(!($bit & (1<<$i)))
$ords[$i] = ++$iter;
for($s = 0; $s <= 50; ++$s){
if($dp[$bit][$s] == PHP_INT_MAX)continue;
foreach($ords as $p0 => $p1){
$ns = ($p0-$con) & 1 ? $B[$p0] : $A[$p0];
if($ns >= $s){
$nb = $bit | (1<<$p0);
$dp[$nb][$ns] = min($dp[$nb][$ns], $dp[$bit][$s] + abs($p1 - $con));
}
}
}
}
$min = min($dp[(1<<$N)-1]);
if($min == PHP_INT_MAX){
echo -1;
}else{
echo $min;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02400 | PHP | Accepted | <?php
$r=trim(fgets(STDIN));
printf("%f %f",$r*$r*pi(),2*$r*pi());
#printf("%f %f",M_PI*$r*$r,M_PI*2*$r);
?> | Here is a piece of code written in PHP:
<?php
$r=trim(fgets(STDIN));
printf("%f %f",$r*$r*pi(),2*$r*pi());
#printf("%f %f",M_PI*$r*$r,M_PI*2*$r);
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03693 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d %d", $r, $g, $b);
$amari = (10 * $g + $b) % 4;
if($amari == 0) {
echo "YES";
} else {
echo "NO";
}
?> | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d %d", $r, $g, $b);
$amari = (10 * $g + $b) % 4;
if($amari == 0) {
echo "YES";
} else {
echo "NO";
}
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02772 | PHP | Accepted | <?php
fgets(STDIN);
$txt = rtrim(fgets(STDIN));
$guusuu = [];
$txt = explode(" ", $txt);
foreach($txt as $t){
if($t % 2 == 0){
$guusuu[] = $t;
}
}
$c = 0;
foreach($guusuu as $g){
if($g % 3 == 0 || $g % 5 == 0){
$c++;
}
}
if(count($guusuu) == $c)
echo "APPROVED";
else
echo "DENIED"; | Here is a piece of code written in PHP:
<?php
fgets(STDIN);
$txt = rtrim(fgets(STDIN));
$guusuu = [];
$txt = explode(" ", $txt);
foreach($txt as $t){
if($t % 2 == 0){
$guusuu[] = $t;
}
}
$c = 0;
foreach($guusuu as $g){
if($g % 3 == 0 || $g % 5 == 0){
$c++;
}
}
if(count($guusuu) == $c)
echo "APPROVED";
else
echo "DENIED";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02271 | PHP | Accepted | <?php
//1行目の空白までのデータをもらって$n1に入れる
fscanf(STDIN, '%d',$n);
//2行目をもらってきて、文字列から空白のスペースを取り除く
$line=trim(fgets(STDIN));
//空白を境目にして、文字列から配列を作る
$line=explode(' ',$line);
//配列の要素を一つずつint型にキャストする
$A=array_map(function ($val) {
return (int)$val;
},$line);
//昇順に並び替える
sort($A);
//$Aの合計値
$sum=array_sum($A);
//3行目の空白までのデータをもらって$n2に入れる
fscanf(STDIN,'%d',$q);
//探索済みの配列を格納するための変数
//4行目の文字列を配列にして格納
$line=explode(' ',trim(fgets(STDIN)));
$arr=array();
// v($line);
foreach($line as $l) {
$l = (int)$l;
//Aの合計値より大きければ不可能
if($l > $sum) {
echo "no\n";
$arr[$l] = false;
//既に探索済み
}elseif(isset($arr[$l])) {
echo $arr[$l] ? "yes\n" : "no\n";
}else {
$bool = cal(0,$l);
$arr[$l]=$bool;
echo $bool ? "yes\n" : "no\n";
}
}
function cal($i, $l){
global $n, $A;
if($l === 0) {
return true;
}elseif($i === $n) {
return false;
}elseif(cal($i + 1,$l)) {
return true;
}elseif(cal($i+1,$l-$A[$i])) {
return true;
}
return false;
}
| Here is a piece of code written in PHP:
<?php
//1行目の空白までのデータをもらって$n1に入れる
fscanf(STDIN, '%d',$n);
//2行目をもらってきて、文字列から空白のスペースを取り除く
$line=trim(fgets(STDIN));
//空白を境目にして、文字列から配列を作る
$line=explode(' ',$line);
//配列の要素を一つずつint型にキャストする
$A=array_map(function ($val) {
return (int)$val;
},$line);
//昇順に並び替える
sort($A);
//$Aの合計値
$sum=array_sum($A);
//3行目の空白までのデータをもらって$n2に入れる
fscanf(STDIN,'%d',$q);
//探索済みの配列を格納するための変数
//4行目の文字列を配列にして格納
$line=explode(' ',trim(fgets(STDIN)));
$arr=array();
// v($line);
foreach($line as $l) {
$l = (int)$l;
//Aの合計値より大きければ不可能
if($l > $sum) {
echo "no\n";
$arr[$l] = false;
//既に探索済み
}elseif(isset($arr[$l])) {
echo $arr[$l] ? "yes\n" : "no\n";
}else {
$bool = cal(0,$l);
$arr[$l]=$bool;
echo $bool ? "yes\n" : "no\n";
}
}
function cal($i, $l){
global $n, $A;
if($l === 0) {
return true;
}elseif($i === $n) {
return false;
}elseif(cal($i + 1,$l)) {
return true;
}elseif(cal($i+1,$l-$A[$i])) {
return true;
}
return false;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02384 | PHP | Accepted | <?php
namespace egg1to3;
class Dice
{
protected $top;
protected $front;
protected $left;
protected $right;
protected $back;
protected $bottom;
public function __construct($arr)
{
$this->top = (int)$arr['top'];
$this->front = (int)$arr['front'];
$this->right = (int)$arr['right'];
$this->left = (int)$arr['left'];
$this->back = (int)$arr['back'];
$this->bottom = (int)$arr['bottom'];
}
public function parse($str, $dump = false)
{
for ($i = 0, $len = strlen($str); $i < $len; $i++) {
$direction = $str[$i];
$this->move($direction);
}
if ($dump) {
echo $this->top, PHP_EOL;
}
}
//指定された値を持つ面を上面に移動させる
public function positionChange($n)
{
$cnt = 0;
while ($this->top !== $n) {
if ($cnt === 4) {
$this->move('E');
$this->move('E');
break;
} elseif ($cnt === 3) {
$this->move('N');
$this->move('E');
} else {
$this->move('N');
}
$cnt++;
}
}
public function rotate($left = false)
{
$this->parse($left ? 'NES' : 'NWS');
}
//指定された面の値を取得
public function getNumber($from)
{
return $this->{$from};
}
protected function move($direction)
{
$top = $this->top;
switch ($direction) {
case 'S':
$this->top = $this->back;
$this->back = $this->bottom;
$this->bottom = $this->front;
$this->front = $top;
break;
case 'N':
$this->top = $this->front;
$this->front = $this->bottom;
$this->bottom = $this->back;
$this->back = $top;
break;
case 'E':
$this->top = $this->left;
$this->left = $this->bottom;
$this->bottom = $this->right;
$this->right = $top;
break;
case 'W':
$this->top = $this->right;
$this->right = $this->bottom;
$this->bottom = $this->left;
$this->left = $top;
break;
default:
new Error('error');
}
}
}
$line = trim(fgets(STDIN));
$nums = explode(' ', $line);
$keys = explode(',', 'top,front,right,left,back,bottom');
$arr = array_combine($keys, $nums);
fscanf(STDIN, '%d', $q);
for ($i = 0; $i < $q; $i++) {
fscanf(STDIN, '%d %d', $top, $front);
$dice = new Dice($arr);
$dice->positionChange($top);
while ($dice->getNumber('front') !== $front) {
$dice->rotate();
}
echo $dice->getNumber('right'), PHP_EOL;
} | Here is a piece of code written in PHP:
<?php
namespace egg1to3;
class Dice
{
protected $top;
protected $front;
protected $left;
protected $right;
protected $back;
protected $bottom;
public function __construct($arr)
{
$this->top = (int)$arr['top'];
$this->front = (int)$arr['front'];
$this->right = (int)$arr['right'];
$this->left = (int)$arr['left'];
$this->back = (int)$arr['back'];
$this->bottom = (int)$arr['bottom'];
}
public function parse($str, $dump = false)
{
for ($i = 0, $len = strlen($str); $i < $len; $i++) {
$direction = $str[$i];
$this->move($direction);
}
if ($dump) {
echo $this->top, PHP_EOL;
}
}
//指定された値を持つ面を上面に移動させる
public function positionChange($n)
{
$cnt = 0;
while ($this->top !== $n) {
if ($cnt === 4) {
$this->move('E');
$this->move('E');
break;
} elseif ($cnt === 3) {
$this->move('N');
$this->move('E');
} else {
$this->move('N');
}
$cnt++;
}
}
public function rotate($left = false)
{
$this->parse($left ? 'NES' : 'NWS');
}
//指定された面の値を取得
public function getNumber($from)
{
return $this->{$from};
}
protected function move($direction)
{
$top = $this->top;
switch ($direction) {
case 'S':
$this->top = $this->back;
$this->back = $this->bottom;
$this->bottom = $this->front;
$this->front = $top;
break;
case 'N':
$this->top = $this->front;
$this->front = $this->bottom;
$this->bottom = $this->back;
$this->back = $top;
break;
case 'E':
$this->top = $this->left;
$this->left = $this->bottom;
$this->bottom = $this->right;
$this->right = $top;
break;
case 'W':
$this->top = $this->right;
$this->right = $this->bottom;
$this->bottom = $this->left;
$this->left = $top;
break;
default:
new Error('error');
}
}
}
$line = trim(fgets(STDIN));
$nums = explode(' ', $line);
$keys = explode(',', 'top,front,right,left,back,bottom');
$arr = array_combine($keys, $nums);
fscanf(STDIN, '%d', $q);
for ($i = 0; $i < $q; $i++) {
fscanf(STDIN, '%d %d', $top, $front);
$dice = new Dice($arr);
$dice->positionChange($top);
while ($dice->getNumber('front') !== $front) {
$dice->rotate();
}
echo $dice->getNumber('right'), PHP_EOL;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03573 | PHP | Accepted | <?php
list($a, $b, $c) = ints();
if ($a === $b) echo $c;
if ($a === $c) echo $b;
if ($b === $c) echo $a;
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
| Here is a piece of code written in PHP:
<?php
list($a, $b, $c) = ints();
if ($a === $b) echo $c;
if ($a === $c) echo $b;
if ($b === $c) echo $a;
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03416 | PHP | Accepted | <?php
list($a, $b) = ints();
$cnt = 0;
for ($i = $a; $i <= $b; $i++) {
$s = strval($i);
if ($s[0] === $s[4] && $s[1] === $s[3]) $cnt++;
}
echo $cnt;
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
} | Here is a piece of code written in PHP:
<?php
list($a, $b) = ints();
$cnt = 0;
for ($i = $a; $i <= $b; $i++) {
$s = strval($i);
if ($s[0] === $s[4] && $s[1] === $s[3]) $cnt++;
}
echo $cnt;
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02416 | PHP | Accepted | <?php
while(true){
$x = trim(fgets(STDIN));
if($x == 0) break;
$sum = 0;
for($i = 0; $i < strlen($x); $i++){
$sum += $x[$i];
}
echo $sum."\n";
} | Here is a piece of code written in PHP:
<?php
while(true){
$x = trim(fgets(STDIN));
if($x == 0) break;
$sum = 0;
for($i = 0; $i < strlen($x); $i++){
$sum += $x[$i];
}
echo $sum."\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03578 | PHP | Accepted | <?php
// define('DEBUG', true);
define('DEBUG', false);
// define('MOD', 1000000007);
fscanf(STDIN, "%d", $M);
$a = explode(" ", trim(fgets(STDIN)));
fscanf(STDIN, "%d", $N);
$b = explode(" ", trim(fgets(STDIN)));
foreach ($a as $v) {
$arr[$v]++;
}
foreach ($b as $v) {
if (!isset($arr[$v])) {
echo "NO\n";
exit;
}
$arr[$v]--;
if ($arr[$v] < 0) {
echo "NO\n";
exit;
}
}
echo "YES\n";
| Here is a piece of code written in PHP:
<?php
// define('DEBUG', true);
define('DEBUG', false);
// define('MOD', 1000000007);
fscanf(STDIN, "%d", $M);
$a = explode(" ", trim(fgets(STDIN)));
fscanf(STDIN, "%d", $N);
$b = explode(" ", trim(fgets(STDIN)));
foreach ($a as $v) {
$arr[$v]++;
}
foreach ($b as $v) {
if (!isset($arr[$v])) {
echo "NO\n";
exit;
}
$arr[$v]--;
if ($arr[$v] < 0) {
echo "NO\n";
exit;
}
}
echo "YES\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03778 | PHP | Accepted | <?php
fscanf(STDIN,"%d %d %d",$w,$a,$b);
if(abs($a-$b) > $w){
echo abs($a-$b)-$w."\n";
}else{
echo "0\n";
} | Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d %d %d",$w,$a,$b);
if(abs($a-$b) > $w){
echo abs($a-$b)-$w."\n";
}else{
echo "0\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p04035 | PHP | Accepted | <?php
list($n, $l) = ints();
$a = ints();
$max = 0;
$maxpos = -1;
for($i = 0; $i < $n-1; $i++){
$sum = $a[$i] + $a[$i+1];
if($max < $sum){
$max = $sum;
$maxpos = $i + 1;
}
}
if($max >= $l){
echo "Possible\n";
for($i = 1; $i < $maxpos;$i++){
echo $i,"\n";
}
for($i = $n - 1 ; $i >= $maxpos;$i--){
echo $i,"\n";
}
}else{
echo "Impossible\n";
}
function str(){
return trim(fgets(STDIN));
}
function ints(){
return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
return intval(trim(fgets(STDIN)));
}
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(" ", $val)."\n";
}else{
echo "array:array\n";
foreach($val as $row){
echo implode(" ", $row)."\n";
}
}
}else{
echo $val."\n";
}
} | Here is a piece of code written in PHP:
<?php
list($n, $l) = ints();
$a = ints();
$max = 0;
$maxpos = -1;
for($i = 0; $i < $n-1; $i++){
$sum = $a[$i] + $a[$i+1];
if($max < $sum){
$max = $sum;
$maxpos = $i + 1;
}
}
if($max >= $l){
echo "Possible\n";
for($i = 1; $i < $maxpos;$i++){
echo $i,"\n";
}
for($i = $n - 1 ; $i >= $maxpos;$i--){
echo $i,"\n";
}
}else{
echo "Impossible\n";
}
function str(){
return trim(fgets(STDIN));
}
function ints(){
return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
return intval(trim(fgets(STDIN)));
}
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(" ", $val)."\n";
}else{
echo "array:array\n";
foreach($val as $row){
echo implode(" ", $row)."\n";
}
}
}else{
echo $val."\n";
}
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02706 | PHP | Accepted | <?php
fscanf(STDIN,"%d %d",$n,$m);
$a = explode(" ", trim(fgets(STDIN)));
foreach($a as $value){
$n -= $value;
if($n < 0){
echo -1;
return;
}
}
echo $n; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN,"%d %d",$n,$m);
$a = explode(" ", trim(fgets(STDIN)));
foreach($a as $value){
$n -= $value;
if($n < 0){
echo -1;
return;
}
}
echo $n;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03834 | PHP | Accepted | <?php
$items = explode(',',trim(fgets(STDIN)));
echo $items[0].' '.$items[1].' '.$items[2];
?> | Here is a piece of code written in PHP:
<?php
$items = explode(',',trim(fgets(STDIN)));
echo $items[0].' '.$items[1].' '.$items[2];
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03260 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d", $a, $b);
if ($a === 2 || $b === 2) {
echo 'No';
} else {
echo 'Yes';
}
| Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d", $a, $b);
if ($a === 2 || $b === 2) {
echo 'No';
} else {
echo 'Yes';
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02948 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d", $n, $m);
while ($n--) {
fscanf(STDIN, "%d %d", $a, $b);
$w[$a][] = $b;
}
$x = 0;
$q = new SplMaxHeap();
for ($i = 1; $i <= $m; $i++) {
if (isset($w[$i])) {
foreach ($w[$i] as $b) $q->insert($b);
}
if (!$q->isEmpty()) {
$x += $q->extract();
}
}
echo $x; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d", $n, $m);
while ($n--) {
fscanf(STDIN, "%d %d", $a, $b);
$w[$a][] = $b;
}
$x = 0;
$q = new SplMaxHeap();
for ($i = 1; $i <= $m; $i++) {
if (isset($w[$i])) {
foreach ($w[$i] as $b) $q->insert($b);
}
if (!$q->isEmpty()) {
$x += $q->extract();
}
}
echo $x;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p00710 | PHP | Accepted | <?php
while(true){
list($n,$r) = explode(" ",trim(fgets(STDIN)));
if($n == 0 && $r == 0) break;
$arr = [];
for($i = $n; $i >= 1; $i--){
$arr[] = $i;
}
for($i = 0; $i < $r; $i++){
list($p,$c) = explode(" ",trim(fgets(STDIN)));
$arr = array_merge(array_splice($arr,$p-1,$c),$arr);
}
echo $arr[0]."\n";
} | Here is a piece of code written in PHP:
<?php
while(true){
list($n,$r) = explode(" ",trim(fgets(STDIN)));
if($n == 0 && $r == 0) break;
$arr = [];
for($i = $n; $i >= 1; $i--){
$arr[] = $i;
}
for($i = 0; $i < $r; $i++){
list($p,$c) = explode(" ",trim(fgets(STDIN)));
$arr = array_merge(array_splice($arr,$p-1,$c),$arr);
}
echo $arr[0]."\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02419 | PHP | Accepted | <?php
$W = fgets(STDIN);
$W = trim($W);
$count = 0;
while (false !== ($line = fgets(STDIN))) {
$line = trim($line);
if ('END_OF_TEXT' === $line) {
break;
}
$words = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
$count += array_reduce($words, function ($carry, $item) use ($W) { return (strtolower($W) === strtolower($item)) ? $carry+1 : $carry; }, 0);
}
echo "$count\n"; | Here is a piece of code written in PHP:
<?php
$W = fgets(STDIN);
$W = trim($W);
$count = 0;
while (false !== ($line = fgets(STDIN))) {
$line = trim($line);
if ('END_OF_TEXT' === $line) {
break;
}
$words = preg_split('/\s+/', $line, -1, PREG_SPLIT_NO_EMPTY);
$count += array_reduce($words, function ($carry, $item) use ($W) { return (strtolower($W) === strtolower($item)) ? $carry+1 : $carry; }, 0);
}
echo "$count\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02622 | PHP | Accepted | <?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
$S = str_split($S);
$T = str_split($T);
$r = 0;
for ($i=0;$i < count($S);$i++) {
if ($S[$i] != $T[$i]) $r++;
}
echo $r; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%s", $S);
fscanf(STDIN, "%s", $T);
$S = str_split($S);
$T = str_split($T);
$r = 0;
for ($i=0;$i < count($S);$i++) {
if ($S[$i] != $T[$i]) $r++;
}
echo $r;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03777 | PHP | Accepted | <?php
fscanf(STDIN, '%s %s', $a, $b);
if($a == $b){
print 'H';
}else{
print 'D';
} | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, '%s %s', $a, $b);
if($a == $b){
print 'H';
}else{
print 'D';
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02729 | PHP | Accepted | <?php
fscanf(STDIN, "%d %d", $n, $m);
$res = 0;
if ($n > 1) $res += $n * ($n - 1) / 2;
if ($m > 1) $res += $m * ($m - 1) / 2;
echo $res; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%d %d", $n, $m);
$res = 0;
if ($n > 1) $res += $n * ($n - 1) / 2;
if ($m > 1) $res += $m * ($m - 1) / 2;
echo $res;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03425 | PHP | Accepted | <?php
list($n) = ints();
for ($i = 0; $i < $n; $i++) {
list($s[]) = strs();
}
for ($i = 0; $i < $n; $i++) {
if (isset($a[$s[$i][0]])) $a[$s[$i][0]]++;
else $a[$s[$i][0]] = 1;
}
$m = ['M', 'A', 'R', 'C', 'H'];
$cnt = 0;
for ($i = 0; $i < 3; $i++) {
for ($j = $i + 1; $j < 4; $j++) {
for ($k = $j + 1; $k < 5; $k++) {
$cnt += ($a[$m[$i]] ?? 0) * ($a[$m[$j]] ?? 0) * ($a[$m[$k]] ?? 0);
}
}
}
echo $cnt;
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
return explode(' ', trim(fgets(STDIN)));
}
| Here is a piece of code written in PHP:
<?php
list($n) = ints();
for ($i = 0; $i < $n; $i++) {
list($s[]) = strs();
}
for ($i = 0; $i < $n; $i++) {
if (isset($a[$s[$i][0]])) $a[$s[$i][0]]++;
else $a[$s[$i][0]] = 1;
}
$m = ['M', 'A', 'R', 'C', 'H'];
$cnt = 0;
for ($i = 0; $i < 3; $i++) {
for ($j = $i + 1; $j < 4; $j++) {
for ($k = $j + 1; $k < 5; $k++) {
$cnt += ($a[$m[$i]] ?? 0) * ($a[$m[$j]] ?? 0) * ($a[$m[$k]] ?? 0);
}
}
}
echo $cnt;
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
function strs()
{
return explode(' ', trim(fgets(STDIN)));
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03574 | PHP | Accepted | <?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
list($H,$W) = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$H;$i++) {
$S[]=trim(fgets(STDIN));
}
for($i=0;$i<$H;$i++) {
for($j=0;$j<$W;$j++) {
if ($S[$i][$j]==".") {
//空きマスの場合は数えて置き換える
$S[$i][$j]=countbomb($i,$j);
}
}
}
foreach($S as $l) {
printf("%s\n",$l);
}
function countbomb($h,$w) {
global $S,$H,$W;
$cnt=0;
$hfrom=max($h-1,0);
$hto =min($h+1,$H);
$wfrom=max($w-1,0);
$wto =min($w+1,$W);
//printf("%d %d %d %d %d %d\n",$h,$w,$hfrom,$hto,$wfrom,$wto);
for($i=$hfrom;$i<=$hto;$i++) {
for($j=$wfrom;$j<=$wto;$j++) {
if ($S[$i][$j]=="#") $cnt++;
}
}
return $cnt;
}
| Here is a piece of code written in PHP:
<?php
error_reporting(0);
//$A = explode(" ",trim(fgets(STDIN)));
list($H,$W) = explode(" ",trim(fgets(STDIN)));
for($i=0;$i<$H;$i++) {
$S[]=trim(fgets(STDIN));
}
for($i=0;$i<$H;$i++) {
for($j=0;$j<$W;$j++) {
if ($S[$i][$j]==".") {
//空きマスの場合は数えて置き換える
$S[$i][$j]=countbomb($i,$j);
}
}
}
foreach($S as $l) {
printf("%s\n",$l);
}
function countbomb($h,$w) {
global $S,$H,$W;
$cnt=0;
$hfrom=max($h-1,0);
$hto =min($h+1,$H);
$wfrom=max($w-1,0);
$wto =min($w+1,$W);
//printf("%d %d %d %d %d %d\n",$h,$w,$hfrom,$hto,$wfrom,$wto);
for($i=$hfrom;$i<=$hto;$i++) {
for($j=$wfrom;$j<=$wto;$j++) {
if ($S[$i][$j]=="#") $cnt++;
}
}
return $cnt;
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03999 | PHP | Accepted | <?php
//error_reporting(0);
$S = trim(fgets(STDIN));
//list($D,$G) = explode(" ",trim(fgets(STDIN)));
//$a = explode(" ",trim(fgets(STDIN)));
$l = strlen($S);
$sum = 0;
for($mask = 0; $mask < (1 << ($l-1)); ++$mask){
$s="";
for($i = 0; $i < $l; ++$i){
if($mask >> $i & 1){
$s = $s . $S[$i] . "+";
}else{
$s = $s . $S[$i];
}
}
$sum += array_sum(explode("+",$s));
}
printf("%d\n",$sum);
| Here is a piece of code written in PHP:
<?php
//error_reporting(0);
$S = trim(fgets(STDIN));
//list($D,$G) = explode(" ",trim(fgets(STDIN)));
//$a = explode(" ",trim(fgets(STDIN)));
$l = strlen($S);
$sum = 0;
for($mask = 0; $mask < (1 << ($l-1)); ++$mask){
$s="";
for($i = 0; $i < $l; ++$i){
if($mask >> $i & 1){
$s = $s . $S[$i] . "+";
}else{
$s = $s . $S[$i];
}
}
$sum += array_sum(explode("+",$s));
}
printf("%d\n",$sum);
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03493 | PHP | Accepted | <?php
fscanf(STDIN, "%s", $s);
$cnt = 0;
for ($i = 0; $i < 3; $i++) {
if (substr($s ,$i ,1) === "1") { $cnt++; }
}
echo($cnt.PHP_EOL);
?> | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, "%s", $s);
$cnt = 0;
for ($i = 0; $i < 3; $i++) {
if (substr($s ,$i ,1) === "1") { $cnt++; }
}
echo($cnt.PHP_EOL);
?>
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p04033 | PHP | Accepted | <?php
list($a, $b) = ints();
if ($a <= 0 && $b >= 0) exit('Zero');
$cntMinus = max(0, -$a) - max(0, - ($b + 1));
echo $cntMinus % 2 ? 'Negative' : 'Positive';
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
| Here is a piece of code written in PHP:
<?php
list($a, $b) = ints();
if ($a <= 0 && $b >= 0) exit('Zero');
$cntMinus = max(0, -$a) - max(0, - ($b + 1));
echo $cntMinus % 2 ? 'Negative' : 'Positive';
function ints()
{
return array_map('intval', explode(' ', trim(fgets(STDIN))));
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03721 | PHP | Accepted | <?php
# 試行回数 番号
fscanf(STDIN, "%d %d", $op_times, $number);
# 配列にキーの値がいくつあるか記録する
while($input = fscanf(STDIN, "%d %d", $a, $b)) {
$tmp[$a] = isset($tmp[$a]) ? $tmp[$a] + $b: $b;
}
# キーで配列昇順
ksort($tmp);
# 配列に値を埋める
foreach ($tmp as $index => $item) {
if ($number <= $item) {
$target = $index;
break;
} else{
$number = $number - $item;
}
}
# 出力
echo $target;
| Here is a piece of code written in PHP:
<?php
# 試行回数 番号
fscanf(STDIN, "%d %d", $op_times, $number);
# 配列にキーの値がいくつあるか記録する
while($input = fscanf(STDIN, "%d %d", $a, $b)) {
$tmp[$a] = isset($tmp[$a]) ? $tmp[$a] + $b: $b;
}
# キーで配列昇順
ksort($tmp);
# 配列に値を埋める
foreach ($tmp as $index => $item) {
if ($number <= $item) {
$target = $index;
break;
} else{
$number = $number - $item;
}
}
# 出力
echo $target;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03477 | PHP | Accepted | <?php
$a = explode(" ",trim(fgets(STDIN)));
$ans=$a[0]+$a[1]-$a[2]-$a[3];
if($ans>0){
echo "Left";
}elseif($ans==0){
echo "Balanced";
}else{
echo "Right";
} | Here is a piece of code written in PHP:
<?php
$a = explode(" ",trim(fgets(STDIN)));
$ans=$a[0]+$a[1]-$a[2]-$a[3];
if($ans>0){
echo "Left";
}elseif($ans==0){
echo "Balanced";
}else{
echo "Right";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p03370 | PHP | Accepted | <?php
// B
fscanf(STDIN, '%d %d', $n, $x);
for ($i = 0; $i < $n; $i++) fscanf(STDIN, '%d', $m[]);
echo $n + intdiv(($x - array_sum($m)), min($m)); | Here is a piece of code written in PHP:
<?php
// B
fscanf(STDIN, '%d %d', $n, $x);
for ($i = 0; $i < $n; $i++) fscanf(STDIN, '%d', $m[]);
echo $n + intdiv(($x - array_sum($m)), min($m));
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02409 | PHP | Accepted | <?php
(new Main)->execute();
class Main
{
public function execute()
{
$house = new House();
$n = getInput();
for ($i = 0; $i < $n; $i++) {
fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);
$house->put($b, $f, $r, $v);
}
$tenant = $house->merge();
echo $house->merge2($tenant);
}
}
class House
{
private $rooms;
private $floors;
private $buildings;
public function __construct()
{
$this->rooms = array_fill_keys(range(1, 10), 0);
$this->floors = array_fill_keys(range(1, 3), $this->rooms);
$this->buildings = array_fill_keys(range(1, 4), $this->floors);
}
public function put($b, $f, $r, $v)
{
$this->buildings[$b][$f][$r] += $v;
}
public function merge()
{
foreach ($this->buildings as $floors) {
$floor = array();
foreach ($floors as $rooms) {
$floor[] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
}
$tenant[] = implode('', $floor);
}
return $tenant;
}
public function merge2($tenant)
{
return implode(str_repeat('#', 20) . "\n", $tenant);
}
}
function getInput()
{
return trim(fgets(STDIN));
} | Here is a piece of code written in PHP:
<?php
(new Main)->execute();
class Main
{
public function execute()
{
$house = new House();
$n = getInput();
for ($i = 0; $i < $n; $i++) {
fscanf(STDIN, '%d %d %d %d', $b, $f, $r, $v);
$house->put($b, $f, $r, $v);
}
$tenant = $house->merge();
echo $house->merge2($tenant);
}
}
class House
{
private $rooms;
private $floors;
private $buildings;
public function __construct()
{
$this->rooms = array_fill_keys(range(1, 10), 0);
$this->floors = array_fill_keys(range(1, 3), $this->rooms);
$this->buildings = array_fill_keys(range(1, 4), $this->floors);
}
public function put($b, $f, $r, $v)
{
$this->buildings[$b][$f][$r] += $v;
}
public function merge()
{
foreach ($this->buildings as $floors) {
$floor = array();
foreach ($floors as $rooms) {
$floor[] = sprintf(' %s%s', implode(' ', $rooms), PHP_EOL);
}
$tenant[] = implode('', $floor);
}
return $tenant;
}
public function merge2($tenant)
{
return implode(str_repeat('#', 20) . "\n", $tenant);
}
}
function getInput()
{
return trim(fgets(STDIN));
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02682 | PHP | Accepted | <?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($A,$B,$C,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
printf("%d\n",min($A,$K)-max($K-($A+$B),0));
| Here is a piece of code written in PHP:
<?php
//$N = (int)trim(fgets(STDIN));
//$S = trim(fgets(STDIN));
list($A,$B,$C,$K) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
//$A = array_map('intval',explode(" ",trim(fgets(STDIN))));
printf("%d\n",min($A,$K)-max($K-($A+$B),0));
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02946 | PHP | Accepted | <?php
fscanf(STDIN, '%d %d', $k, $x);
$start = $x - $k + 1;
$end = $x + $k - 1;
$ans = '';
for($start; $start <= $end; $start++) {
$ans .= ' '. $start;
}
echo trim($ans), PHP_EOL; | Here is a piece of code written in PHP:
<?php
fscanf(STDIN, '%d %d', $k, $x);
$start = $x - $k + 1;
$end = $x + $k - 1;
$ans = '';
for($start; $start <= $end; $start++) {
$ans .= ' '. $start;
}
echo trim($ans), PHP_EOL;
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02922 | PHP | Accepted | <?php
list($A, $B) = explode(' ', trim(fgets(STDIN)));
echo ceil(($B - $A) / ($A - 1)) + 1, "\n";
| Here is a piece of code written in PHP:
<?php
list($A, $B) = explode(' ', trim(fgets(STDIN)));
echo ceil(($B - $A) / ($A - 1)) + 1, "\n";
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
p02403 | PHP | Accepted | <?php
// Structured Program I - Print a Rectangle
while(true){
$data = explode(" ",trim(fgets(STDIN)));
$H = $data[0];
$W = $data[1];
if($H == 0 && $W == 0) break;// ??\????????????
for($i = 0; $i < $H; $i++){
for($j = 0; $j < $W; $j++){
echo "#";
}
echo "\n";
}
echo "\n";
} | Here is a piece of code written in PHP:
<?php
// Structured Program I - Print a Rectangle
while(true){
$data = explode(" ",trim(fgets(STDIN)));
$H = $data[0];
$W = $data[1];
if($H == 0 && $W == 0) break;// ??\????????????
for($i = 0; $i < $H; $i++){
for($j = 0; $j < $W; $j++){
echo "#";
}
echo "\n";
}
echo "\n";
}
Do you think this code will compile successfully? Answer 'Yes' or 'No'. | Yes |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.