Submission #123073

#TimeUsernameProblemLanguageResultExecution timeMemory
123073bjpark0805물탱크 (KOI18_watertank)C++14
6 / 100
3058 ms394724 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(){} 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 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))); } blockq bq; 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); bq = pq.top(); int x = bq.x; int y = bq.y; int val = bq.value; pq.pop(); //count2.at(pq.top().x).at(pq.top().y)=1; if(block.at(x).at(y) < val) continue; 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]); bq.x = nx; bq.y = ny; bq.value = block.at(nx).at(ny); } 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]); bq.x = x; bq.y = y; bq.value = 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(nx).at(ny)=block.at(x).at(y); bq.x = nx; bq.y = ny; bq.value = block.at(nx).at(ny); } 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); bq.x = x; bq.y = y; bq.value = block.at(x).at(y); } pq.push(bq); } } 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]); bq.x = nx; bq.y = ny; bq.value = block.at(nx).at(ny); } 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]); bq.x = x; bq.y = y; bq.value = 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(nx).at(ny)=block.at(x).at(y); bq.x = nx; bq.y = ny; bq.value = block.at(nx).at(ny); } 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); bq.x = x; bq.y = y; bq.value = block.at(x).at(y); } pq.push(bq); } } } } } for(i=0;i<n;++i){ for(j=0;j<m;++j){ sum += block.at(i).at(j); } } cout << sum << endl; }
#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...