当我输入超过20作为输入时,我收到此错误 这是我的脚本。最多20作为输入值我可以使用set_time_limit(0); ini_set(“memory_limit”,“2000M”)在我的本地运行;或更多,但它并不关心hackerrank平台。我需要用php修复hackerrank 输入可能高达65
<?php
function generateInputCode($nbit) {
$nlist = array();
if($nbit == 2) {
$nlist = array('00', '01', '11', '10');
showResult($nlist,$nbit);
}
elseif($nbit == 3) {
$nlist = array('000', '001', '011', '010', '110', '111', '101', '100');
showResult($nlist,$nbit);
}
else{
$listn = array('000', '001', '011', '010', '110', '111', '101', '100');
for($bit = 4; $bit <= $nbit; $bit++){
$l = count($listn);
$reflectedlistn = array_reverse($listn);
$lista = array();
$listb = array();
array_walk($listn, function(&$value, $key) { $value = '0'.$value; });
$lista = $listn;
array_walk($reflectedlistn, function(&$value, $key) { $value = '1'.$value; });
$listb = $reflectedlistn;
$listn = array_merge($lista,$listb);
}
showResult($listn,$nbit);
}
}
function showResult($listm,$nbit){
$ln = count($listm);
for($i=$ln-$nbit;$i<$ln;$i++){
print $listm[$i]."\n";
}
}
$handle = fopen ("php://stdin","r");
$nbit = (int) fgets($handle);
if($nbit == 1) print 1;
elseif($nbit>1&&$nbit<=65) generateInputCode($nbit);
?>
有人可以建议吗?