paizaオンラインハッカソン5 ミッションRENA 初心者にもわかるPHPでの解答例
<?php
$input = explode(' ', trim(fgets(STDIN)));

$x_max = $input[0];
$y_max = $input[1];
$rect_count = $input[2];

$box_number = array();

$rect_start_point = array();
$rect_goal_point = array();

$check_xy_memo = array();

$answer = 0;

for ($i=1; $i <= $y_max; $i++) { 
	$row = explode(' ', trim(fgets(STDIN)));

	for ($j=1; $j <= $x_max; $j++) { 
		$box_number[$j.'-'.$i] = $row[$j-1];
	}
}

for ($i=0; $i < $rect_count; $i++) { 
	$rect = explode(' ', trim(fgets(STDIN)));
	$rect_start_point[] = array($rect[0], $rect[1]);
	$rect_goal_point[] = array($rect[2], $rect[3]);

	$tmp_sp_x = $rect_start_point[$i][0];
	$tmp_gp_x = $rect_goal_point[$i][0];
	
	for ($j=$tmp_sp_x; $j <= $tmp_gp_x; $j++) { 
		$tmp_sp_y = $rect_start_point[$i][1];
		$tmp_gp_y = $rect_goal_point[$i][1];
		for ($k=$tmp_sp_y; $k <= $tmp_gp_y; $k++) { 
			$key = $j.'-'.$k;
			if (array_search($key, $check_xy_memo) === false) {
				$answer += $box_number[$key];
				$check_xy_memo[] = $key;
			}
		}
	}
}

echo $answer."\n";

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

*
*