Bootstrap

Serial Time!

E. Serial Time!

Problem

The Cereal Guy’s friend Serial Guy likes to watch soap operas. An episode is about to start, and he hasn’t washed his plate yet. But he decided to at least put in under the tap to be filled with water. The plate can be represented by a parallelepiped k × n × m, that is, it has k layers (the first layer is the upper one), each of which is a rectangle n × m with empty squares (‘.’) and obstacles (‘#’). The water can only be present in the empty squares. The tap is positioned above the square (x, y) of the first layer, it is guaranteed that this square is empty. Every minute a cubical unit of water falls into the plate. Find out in how many minutes the Serial Guy should unglue himself from the soap opera and turn the water off for it not to overfill the plate. That is, you should find the moment of time when the plate is absolutely full and is going to be overfilled in the next moment.

Note: the water fills all the area within reach (see sample 4). Water flows in each of the 6 directions, through faces of 1 × 1 × 1 cubes.

有道 翻译
麦片男的朋友Serial Guy喜欢看肥皂剧。一集就要开始了,他还没洗盘子。但他决定至少把它放在水龙头下面,让它装满水。该板可以用一个平行六面体 k × n × m 来表示,即它有 k 层(第一层为上一层),每一层都是一个矩形 n × m ,带有空方块(‘.‘)和障碍物(’#’)。水只能存在于空的方格中。tap位于第一层的方块 (x, y) 上方,保证该方块为空。每分钟有一个立方单位的水落入盘子里。找出连环男应该在多少分钟内从肥皂剧中脱身,然后关掉水,以免水溢满盘子。也就是说,你应该找到一个时刻,当盘子完全满的时候,下一刻会被填满。

注:水充满了触手可及的所有区域(见样例4)。水在的6个方向流过 1 × 1 × 1 立方体的面。

Input

The first line contains three numbers k, n, m (1 ≤ k, n, m ≤ 10) which are the sizes of the plate. Then follow k rectangles consisting of n lines each containing m characters ‘.’ or ‘#’, which represents the “layers” of the plate in the order from the top to the bottom. The rectangles are separated by empty lines (see the samples). The last line contains x and y (1 ≤ x ≤ n, 1 ≤ y ≤ m) which are the tap’s coordinates. x is the number of the line and y is the number of the column. Lines of each layer are numbered from left to right by the integers from 1 to n, columns of each layer are numbered from top to bottom by the integers from 1 to m.

Output

The answer should contain a single number, showing in how many minutes the plate will be filled.

Examples

Input
1 1 1

.

1 1
Output
1
Input
2 1 1

.

#

1 1
Output
1
Input
2 2 2

.#
##

..
..

1 1
Output
5
Input
3 2 2

#.
##

#.
.#

..
..

1 2
Output
7
Input
3 3 3

.#.
###
##.

.##
###
##.

...
...
...

1 1
Output
13

Code

// #include <iostream>
// #include <algorithm>
// #include <cstring>
// #include <sstream>//整型转字符串
// #include <stack>//栈
// #include <deque>//堆/优先队列
// #include <queue>//队列
// #include <map>//映射
// #include <unordered_map>//哈希表
// #include <vector>//容器,存数组的数,表数组的长度
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ll dx[6]={0,0,0,0,1,-1};
ll dy[6]={0,0,1,-1,0,0};
ll dh[6]={1,-1,0,0,0,0};
char a[11][11][11];
ll k,n,m;
ll ans=0;

void dfs(ll h,ll x,ll y)
{
    ans++;
    a[h][x][y]='#';

    for(ll i=0;i<6;i++)
    {
        ll hh=h+dh[i],xx=x+dx[i],yy=y+dy[i];
        if(hh>=1&&hh<=k&&xx>=1&&xx<=n&&yy>=1&&yy<=m&&a[hh][xx][yy]=='.')
            dfs(hh,xx,yy);
    }
}

void solve()
{
    cin>>k>>n>>m;

    for(ll i=1;i<=k;i++)
        for(ll j=1;j<=n;j++)
            for(ll h=1;h<=m;h++)
                cin>>a[i][j][h];

    ll x,y;
    cin>>x>>y;
    dfs(1,x,y);
    cout<<ans<<endl;
}

int main()
{
    ll t=1;
    //cin>>t;

    while(t--) solve();
    
    return 0;
}
;