<?php
// H, W取得
// D取得
for ($h = 0; $h < $height; $h++) {
}
// N取得
// 指定座標を左上として入る大きさを探索する
function search($h, $w) {
global $home, $available, $height, $width;
$available[1][1]++;
$t_max = $width - $w;
for ($s = 1; $s <= $height - $h; $s++) {
for ($t = (1 === $s) ? 2 : 1; $t <= $t_max; $t++) {
if ('0' === substr($home[$h + $s - 1], $w + $t - 1, 1)) { $available[$s][$t]++;
} else if (1 === $t) {
return;
} else {
$t_max = $t - 1;
break;
}
}
}
}
// 探索用データ初期化
for ($s = 1; $s <= $height; $s++) {
for ($t = 1; $t <= $width; $t++) {
$available[$s][$t] = 0;
}
}
// 検索用データ生成
for ($h = 0; $h < $height; $h++) {
for ($w = 0; $w < $width; $w++) {
if (substr($home[$h], $w, 1) === '0') { search($h, $w);
}
}
}
// S, T取得
$output = '';
for ($n = 0; $n < $cnt; $n++) {
if ($h > $height or $w > $width) {
$output .= "0\n";
} else {
$output .= $available[$h][$w]."\n";
}
}
echo $output;
PD9waHAKLy8gSCwgV+WPluW+lwpsaXN0KCRoZWlnaHQsICR3aWR0aCkgPSBleHBsb2RlKCcgJywgdHJpbShmZ2V0cyhTVERJTikpKTsKCi8vIETlj5blvpcKZm9yICgkaCA9IDA7ICRoIDwgJGhlaWdodDsgJGgrKykgewoJJGhvbWVbXSA9IHRyaW0oZmdldHMoU1RESU4pKTsKfQoKLy8gTuWPluW+lwokY250ID0gdHJpbShmZ2V0cyhTVERJTikpOwoKLy8g5oyH5a6a5bqn5qiZ44KS5bem5LiK44Go44GX44Gm5YWl44KL5aSn44GN44GV44KS5o6i57Si44GZ44KLCmZ1bmN0aW9uIHNlYXJjaCgkaCwgJHcpIHsKCWdsb2JhbCAkaG9tZSwgJGF2YWlsYWJsZSwgJGhlaWdodCwgJHdpZHRoOwoJJGF2YWlsYWJsZVsxXVsxXSsrOwoJJHRfbWF4ID0gJHdpZHRoIC0gJHc7Cglmb3IgKCRzID0gMTsgJHMgPD0gJGhlaWdodCAtICRoOyAkcysr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