Submission #145574

#TimeUsernameProblemLanguageResultExecution timeMemory
145574surface03토마토 (3차원) (KOI13_tomato3D)C++14
20 / 20
247 ms13688 KiB
#include<bits/stdc++.h> using namespace std; struct data{ int x,y,z,lev; }; queue<data> que; int m,n,h,a[110][110][110],visit[110][110][110],cnt,tot; int dr[]={1,-1,0,0,0,0},dc[]={0,0,1,-1,0,0},du[]={0,0,0,0,1,-1}; void push(int x,int y,int z,int level){ if(x<1||y<1||z<1||x>n||y>m||z>h||visit[x][y][z]||a[x][y][z]==-1)return; visit[x][y][z]=1; cnt++; que.push({x,y,z,level}); } int bfs(){ data t; while(!que.empty()){ t=que.front(); que.pop(); for(int i=0;i<6;i++){ push(t.x+dr[i],t.y+dc[i],t.z+du[i],t.lev+1); } } return t.lev; } int main(){ scanf("%d%d%d",&m,&n,&h); tot=m*n*h; for(int k=1;k<=h;k++){ for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ scanf("%d",&a[i][j][k]); if(a[i][j][k]==1)push(i,j,k,0); if(a[i][j][k]==-1)tot--; } } } int ans=bfs(); if(tot!=cnt)printf("-1"); else printf("%d",ans); }

Compilation message (stderr)

cc.cpp: In function 'int main()':
cc.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&m,&n,&h);  
     ~~~~~^~~~~~~~~~~~~~~~~~~
cc.cpp:35:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
                 scanf("%d",&a[i][j][k]);  
                 ~~~~~^~~~~~~~~~~~~~~~~~
cc.cpp: In function 'int bfs()':
cc.cpp:26:14: warning: 't.data::lev' may be used uninitialized in this function [-Wmaybe-uninitialized]
     return t.lev;  
              ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...