Submission #120082

#TimeUsernameProblemLanguageResultExecution timeMemory
120082KOMJ01물탱크 (KOI18_watertank)C++14
21 / 100
511 ms180832 KiB
#include <iostream> #include <vector> #include <queue> using namespace std; int n,m,h; vector<vector<int>>garosun,serosun,block,count, count2; int dx[4]={0,0,1,-1}, dy[4]={1,-1,0,0}, d2x[4]={0,0,1,0}, d2y[4]={1,0,0,0}; struct blockq{ int x; int y; int value; blockq(int nx, int ny, int nvalue) : x(nx), y(ny), value(nvalue){} }; struct cmp{ bool operator()(blockq t, blockq u){ return t.value>u.value; } }; priority_queue<blockq, vector<blockq>,cmp>pq; int DFS(int x,int y) { count.at(x).at(y)=1; for(int i=0;i<4;++i) { int nx=x+dx[i], ny=y+dy[i]; if(nx>=0 && nx<n && ny>=0 && ny<m && count.at(nx).at(ny)==0) { if(dx[i]==0) { if(serosun.at(x+d2x[i]).at(y+d2y[i])>=0){ if(block.at(x).at(y)<=serosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>=serosun.at(x+d2x[i]).at(y+d2y[i]))//(x,y)가 더 작다. { block.at(nx).at(ny)=serosun.at(x+d2x[i]).at(y+d2y[i]); } else if(block.at(x).at(y)>=serosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)<=serosun.at(x+d2x[i]).at(y+d2y[i]))//(nx,ny)가 더 작다. { block.at(x).at(y)=serosun.at(x+d2x[i]).at(y+d2y[i]); } else if(block.at(x).at(y)>serosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>serosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>=block.at(x).at(y))//둘다 세로선 이상 { block.at(nx).at(ny)=block.at(x).at(y); } else if(block.at(x).at(y)>serosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>serosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)<=block.at(x).at(y))//둘다 세로선 이상 { block.at(x).at(y)=block.at(nx).at(ny); } DFS(nx,ny); } } if(dy[i]==0) { if(garosun.at(x+d2x[i]).at(y+d2y[i])>=0){ if(block.at(x).at(y)<=garosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>=garosun.at(x+d2x[i]).at(y+d2y[i]))//(x,y)가 더 작다. { block.at(nx).at(ny)=garosun.at(x+d2x[i]).at(y+d2y[i]); } else if(block.at(x).at(y)>=garosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)<=garosun.at(x+d2x[i]).at(y+d2y[i]))//(nx,ny)가 더 작다. { block.at(x).at(y)=garosun.at(x+d2x[i]).at(y+d2y[i]); } else if(block.at(x).at(y)>garosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>garosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>=block.at(x).at(y))//둘다 세로선 이상 { block.at(nx).at(ny)=block.at(x).at(y); } else if(block.at(x).at(y)>garosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)>garosun.at(x+d2x[i]).at(y+d2y[i]) && block.at(nx).at(ny)<=block.at(x).at(y))//둘다 세로선 이상 { block.at(x).at(y)=block.at(nx).at(ny); } DFS(nx,ny); } } if(x==0 || y==0) pq.push(blockq(x,y,block.at(x).at(y))); } } } int main(){ int i, j, sum=0; cin>>n>>m>>h; block.resize(n); count.resize(n); count2.resize(n); for(i=0;i<n;++i) { block.at(i).resize(m,h); count.at(i).resize(m); count2.at(i).resize(m); } garosun.resize(n+1); for(i=0;i<n+1;++i) { garosun.at(i).resize(m); } serosun.resize(n); for(i=0;i<n;++i) { serosun.at(i).resize(m+1); } for(i=0;i<n+1;++i){ for(j=0;j<m;++j){ cin>> garosun.at(i).at(j); } } for(i=0;i<n;++i){ for(j=0;j<m+1;++j){ cin>> serosun.at(i).at(j); } } for(i=0;i<m;++i) { if(garosun.at(0).at(i)>=0 && garosun.at(0).at(i)<block.at(0).at(i)) { block.at(0).at(i)=garosun.at(0).at(i); } if(garosun.at(n).at(i)>=0 && garosun.at(n).at(i)<block.at(n-1).at(i)) { block.at(n-1).at(i)=garosun.at(n).at(i); } } for(i=0;i<n;++i) { if(serosun.at(i).at(0)>=0 && serosun.at(i).at(0)<block.at(i).at(0)) { block.at(i).at(0)=serosun.at(i).at(0); } if(serosun.at(i).at(m)>=0 && serosun.at(i).at(m)<block.at(i).at(m-1)) { block.at(i).at(m-1)=serosun.at(i).at(m); } } for(i=0;i<m;++i) { pq.push(blockq(0,i,block.at(0).at(i))); pq.push(blockq(n-1,i,block.at(n-1).at(i))); } for(i=1;i<n-1;++i) { pq.push(blockq(i,0,block.at(i).at(0))); pq.push(blockq(i,m-1,block.at(i).at(m-1))); } while(!pq.empty()){ for(i=0;i<n;++i) { count.at(i).resize(m); } if(count2.at(pq.top().x).at(pq.top().y)==0) DFS(pq.top().x,pq.top().y); // cout<<pq.top().value<<" "<<pq.top().x<<" "<<pq.top().y<<endl; count2.at(pq.top().x).at(pq.top().y)=1; pq.pop(); } for(i=0;i<n;++i){ for(j=0;j<m;++j){ sum += block.at(i).at(j); } } cout << sum<< endl; }

Compilation message (stderr)

watertank.cpp: In function 'int DFS(int, int)':
watertank.cpp:81:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
#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...