답안 #120082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120082 2019-06-23T08:41:57 Z KOMJ01 물탱크 (KOI18_watertank) C++14
21 / 100
511 ms 180832 KB
#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

watertank.cpp: In function 'int DFS(int, int)':
watertank.cpp:81:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 407 ms 26080 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 356 ms 22232 KB Output is correct
4 Correct 410 ms 23416 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 424 ms 27176 KB Output is correct
7 Correct 345 ms 22648 KB Output is correct
8 Correct 473 ms 180832 KB Output is correct
9 Correct 331 ms 21496 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 511 ms 62840 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -