답안 #647821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647821 2022-10-04T08:13:47 Z ToroTN Flood (IOI07_flood) C++14
10 / 100
142 ms 16852 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define X first
#define Y second
int n,m,x[100005],y[100005],wall1,wall2,a1,b1,a2,b2,go[100005][4],st,d[100005];
int nxt[100005][4],p[100005],rev[100005],num,dir,way,val;
//right=0 down=1 left 2 up=3
vector<pair<pair<int,int>,int > > v;
vector<int> g;
set<int> s;
void dfs(int u)
{
    //printf("->%d: coor = %d %d, dir=%d\n",u,x[u],y[u],dir);
    for(int i=0;i<4;i++)
    {
        way=(dir+2+i)%4;
        if(go[u][way]!=0&&go[u][way]!=p[u])
        {
            if(d[go[u][way]]!=1)
            {
                if(d[go[u][way]]==-1)
                {
                    d[go[u][way]]=0;
                    g.pb(go[u][way]);
                    p[go[u][way]]=u;
                    dir=way;
                    rev[go[u][way]]=nxt[u][way];
                    dfs(go[u][way]);
                    if(val==-1)
                    {
                        for(int j=0;j<g.size();j++)
                        {
                            //printf("%d ",g[i]);
                            d[g[j]]=1;
                        }
                        g.clear();
                    }
                    if(g.size()==0)return;
                }else
                {
                    //printf("last=%lld %lld %lld\n",go[u][way],u,p[u]);
                    //printf("breakloop%d %d\n",u,i);
                    for(int j=0;j<g.size();j++)
                    {
                        //printf("%d ",g[i]);
                        d[g[j]]=1;
                    }
                    //printf("\n");
                    s.erase(nxt[u][way]);
                    num=u;
                    while(1)
                    {
                        if(p[num]==0)break;
                        s.erase(rev[num]);
                        num=p[num];
                    }
                    g.clear();
                    if(g.size()==0)return;
                }
            }
        }
    }
    val=-1;
}
int main()
{
    memset(d,-1,sizeof d);
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x[i],&y[i]);
        v.pb({{x[i],y[i]},i});
    }
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        s.insert(i);
        scanf("%d%d",&wall1,&wall2);
        a1=x[wall1];
        b1=y[wall1];
        a2=x[wall2];
        b2=y[wall2];
        if(a1>a2)
        {
            swap(a1,a2);
            swap(wall1,wall2);
        }
        if(a1<a2)
        {
            go[wall1][1]=wall2;
            go[wall2][3]=wall1;
            nxt[wall1][1]=i;
            nxt[wall2][3]=i;
        }
        if(b1>b2)
        {
            swap(b1,b2);
            swap(wall1,wall2);
        }
        if(b1<b2)
        {
            go[wall1][0]=wall2;
            go[wall2][2]=wall1;
            nxt[wall1][0]=i;
            nxt[wall2][2]=i;
        }
    }
    /*for(int i=0;i<4;i++)
    {
        printf("%d ",go[2][i]);
    }
    printf("\n");*/
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        st=v[i].Y;
        if(d[st]==-1)
        {
            val=0;
            //printf("start=%d\n",st);
            d[st]=0;
            dir=2;
            g.pb(st);
            dfs(st);
            /*for(auto it:s)printf("%d\n",it);
            printf("\n");*/
        }
    }
    printf("%d\n",s.size());
    for(auto it:s)printf("%d\n",it);
}

Compilation message

flood.cpp: In function 'void dfs(int)':
flood.cpp:32:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |                         for(int j=0;j<g.size();j++)
      |                                     ~^~~~~~~~~
flood.cpp:44:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |                     for(int j=0;j<g.size();j++)
      |                                 ~^~~~~~~~~
flood.cpp: In function 'int main()':
flood.cpp:115:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |     for(int i=0;i<v.size();i++)
      |                 ~^~~~~~~~~
flood.cpp:130:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
  130 |     printf("%d\n",s.size());
      |             ~^    ~~~~~~~~
      |              |          |
      |              int        std::set<int>::size_type {aka long unsigned int}
      |             %ld
flood.cpp:69:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   69 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
flood.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   72 |         scanf("%d%d",&x[i],&y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
flood.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     scanf("%d",&m);
      |     ~~~~~^~~~~~~~~
flood.cpp:79:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         scanf("%d%d",&wall1,&wall2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Incorrect 1 ms 724 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 3660 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 70 ms 13248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 75 ms 12480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 142 ms 15480 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 127 ms 16852 KB Output isn't correct
2 Halted 0 ms 0 KB -