using
System;
using
System.Collections.Generic;
class
GFG {
static
int
n;
static
int
curr_i = 0, curr_j = 0;
static
int
duration;
static
List<List<
bool
>> visited =
new
List<List<
bool
>>();
static
void
moveRobot(
int
n,
int
i,
int
j,
int
dx,
int
dy)
{
if
(i < 0 || i >= n || j < 0 || j >= n
|| visited[i][j] ==
true
|| duration == 0) {
return
;
}
curr_i = i;
curr_j = j;
visited[i][j] =
true
;
duration--;
moveRobot(n, i + dx, j + dy, dx, dy);
}
static
void
findUnvisited(
int
p, List<Tuple<
int
,
string
>> periods)
{
Dictionary<
string
, List<
int
>> mp =
new
Dictionary<
string
, List<
int
>>();
mp[
"N"
] =
new
List<
int
>(
new
int
[]{-1, 0});
mp[
"S"
] =
new
List<
int
>(
new
int
[]{1, 0});
mp[
"E"
] =
new
List<
int
>(
new
int
[]{0, 1});
mp[
"W"
] =
new
List<
int
>(
new
int
[]{0, -1});
mp[
"NE"
] =
new
List<
int
>(
new
int
[]{-1, 1});
mp[
"NW"
] =
new
List<
int
>(
new
int
[]{-1, -1});
mp[
"SE"
] =
new
List<
int
>(
new
int
[]{1, 1});
mp[
"SW"
] =
new
List<
int
>(
new
int
[]{1, -1});
for
(
int
i = 0; i < n; i++) {
visited.Add(
new
List<
bool
>());
for
(
int
j = 0; j < n; j++) {
visited[i].Add(
false
);
}
}
for
(
int
i = 0; i < p; i++) {
string
dir = periods[i].Item2;
int
dx = mp[dir][0];
int
dy = mp[dir][1];
int
duration;
if
(i < p - 1) {
duration
= periods[i + 1].Item1
- periods[i].Item1;
}
else
{
duration = (
int
)Math.Sqrt(2) * n;
}
int
next_i = curr_i + dx;
int
next_j = curr_j + dy;
if
(next_i >= 0
&& next_i < n
&& next_j >= 0
&& next_j < n
&& visited[next_i][next_j] ==
false
&& duration > 0) {
moveRobot(n, next_i, next_j, dx, dy);
}
}
int
not_visited = 0;
for
(
int
i = 0; i < n; i++) {
for
(
int
j = 0; j < n; j++) {
if
(visited[i][j] ==
false
) {
not_visited++;
}
}
}
Console.Write(not_visited/2+1);
}
static
void
Main() {
n = 5;
int
p = 6;
List<Tuple<
int
,
string
>> periods =
new
List<Tuple<
int
,
string
>>();
periods.Add(
new
Tuple<
int
,
string
>(0,
"SE"
));
periods.Add(
new
Tuple<
int
,
string
>(1,
"NE"
));
periods.Add(
new
Tuple<
int
,
string
>(2,
"E"
));
periods.Add(
new
Tuple<
int
,
string
>(6,
"SW"
));
periods.Add(
new
Tuple<
int
,
string
>(15,
"N"
));
periods.Add(
new
Tuple<
int
,
string
>(20,
"W"
));
findUnvisited(p, periods);
}
}