# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
4946 |
2014-01-23T13:14:41 Z |
hana5505 |
토마토 (KOI13_tomato) |
C++ |
|
908 ms |
13220 KB |
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
int map[1011][1011];
int aa[1011][1011];
int cnt[1011][1011];
int mx=0;
int gox[4]={0,0,1,-1};
int goy[4]={1,-1,0,0};
void bfs(int x,int y)
{
queue<int> qx,qy,qz;
int tx,ty,tz,i;
aa[x][y]=1;
qx.push(x);
qy.push(y);
qz.push(0);
while(!qx.empty()){
tx=qx.front();
ty=qy.front();
tz=qz.front();
qx.pop();
qy.pop();
qz.pop();
for(i=0;i<4;i++){
if(map[tx+gox[i]][ty+goy[i]]==0 && (aa[tx+gox[i]][ty+goy[i]]==0 || cnt[tx+gox[i]][ty+goy[i]]>tz+1)){
aa[tx+gox[i]][ty+goy[i]]=1;
cnt[tx+gox[i]][ty+goy[i]]=tz+1;
qx.push(tx+gox[i]);
qy.push(ty+goy[i]);
qz.push(tz+1);
}
}
}
}
int main()
{
int m,n,i,j;
scanf("%d %d",&m,&n);
for(i=0;i<=1010;i++){
for(j=0;j<=1010;j++)
map[i][j]=-1;
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++)
scanf("%d",&map[i][j]);
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(map[i][j]==1)
bfs(i,j);
}
}
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
if(map[i][j]==0 && aa[i][j]==0) {printf("-1");return 0;}
if(cnt[i][j]>mx) mx=cnt[i][j];
}
}
printf("%d",mx);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13220 KB |
Output is correct |
2 |
Correct |
0 ms |
13220 KB |
Output is correct |
3 |
Correct |
0 ms |
13220 KB |
Output is correct |
4 |
Correct |
0 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13220 KB |
Output is correct |
2 |
Correct |
0 ms |
13220 KB |
Output is correct |
3 |
Correct |
0 ms |
13220 KB |
Output is correct |
4 |
Correct |
0 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
13220 KB |
Output is correct |
2 |
Correct |
0 ms |
13220 KB |
Output is correct |
3 |
Correct |
0 ms |
13220 KB |
Output is correct |
4 |
Correct |
0 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
13220 KB |
Output is correct |
2 |
Correct |
64 ms |
13220 KB |
Output is correct |
3 |
Correct |
8 ms |
13220 KB |
Output is correct |
4 |
Correct |
0 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13220 KB |
Output is correct |
2 |
Correct |
0 ms |
13220 KB |
Output is correct |
3 |
Correct |
20 ms |
13220 KB |
Output is correct |
4 |
Correct |
4 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
13220 KB |
Output is correct |
2 |
Correct |
4 ms |
13220 KB |
Output is correct |
3 |
Correct |
0 ms |
13220 KB |
Output is correct |
4 |
Correct |
4 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
104 ms |
13220 KB |
Output is correct |
2 |
Correct |
32 ms |
13220 KB |
Output is correct |
3 |
Correct |
44 ms |
13220 KB |
Output is correct |
4 |
Correct |
20 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
172 ms |
13220 KB |
Output is correct |
2 |
Correct |
208 ms |
13220 KB |
Output is correct |
3 |
Correct |
20 ms |
13220 KB |
Output is correct |
4 |
Correct |
16 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
13220 KB |
Output is correct |
2 |
Correct |
116 ms |
13220 KB |
Output is correct |
3 |
Correct |
28 ms |
13220 KB |
Output is correct |
4 |
Correct |
68 ms |
13220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
512 ms |
13220 KB |
Output is correct |
2 |
Correct |
908 ms |
13220 KB |
Output is correct |
3 |
Correct |
128 ms |
13220 KB |
Output is correct |
4 |
Correct |
92 ms |
13220 KB |
Output is correct |