ساعت
۹۰۱۲۳۴۵۶۷۸۹۰۹۰۱۲۳۴۵۶۷۸۹۰
ساعت
دقیقه
۹۰۱۲۳۴۵۶۷۸۹۰۹۰۱۲۳۴۵۶۷۸۹۰
دقیقه
ثانیه
۹۰۱۲۳۴۵۶۷۸۹۰۹۰۱۲۳۴۵۶۷۸۹۰
ثانیه
  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

The Barareh village is on fire due to the attack of the virtual enemy. Several places are already on fire and the fire is spreading fast to other places. Khorzookhan who is the only person remaining alive in the war with the virtual enemy, tries to rescue himself by reaching to the only helicopter in the Barareh villiage.

Suppose the Barareh village is represented by an n×mn \times m grid. At the initial time, some grid cells are on fire. If a cell catches fire at time xx, all its 8 vertex-neighboring cells will catch fire at time x+kx + k. If a cell catches fire, it will be on fire forever. At the initial time, Khorzookhan stands at cell ss and the helicopter is located at cell tt. At any time xx, Khorzookhan can move from its current cell to one of four edge-neighboring cells, located at the left, right, top, or bottom of its current cell if that cell is not on fire at time x+1x + 1. Note that each move takes one second.

Your task is to write a program to find the shortest path from ss to tt avoiding fire.

ورودی

There are multiple test cases in the input. The first line of each test case contains three positive integers n,mn, m and kk (1n,m,k1001 \leq n, m, k \leq 100), where nn and mm indicate the size of the test case grid n×mn \times m, and kk denotes the growth rate of fire. The next nn lines, each contains a string of length mm, where the jjth character of the iith line represents the cell (i,j)(i, j) of the grid. Cells which are on fire at time 00, are presented by character f. There may exist no f in the test case. The helicopter and Khorzookhan are located at cells presented by t and s, respectively. Other cells are filled by - characters. The input terminates with a line containing 0 0 0 which should not be processed.

خروجی

For each test case, output a line containing the shortest time to reach t from s avoiding fire. If it is impossible to reach t from s, write Impossible in the output.

مثال

ورودی نمونه ۱

7 7 2
f------
-f---f-
----f--
-------
------f
---s---
t-----f
3 4 1
t--f
--s-
----
2 2 1
st
f-
2 2 2
st
f-
0 0 0
Plain text

خروجی نمونه ۱

4
Impossible
Impossible
1
Plain text

ارسال پاسخ برای این سؤال
فایلی انتخاب نشده است.