Submission #647661

# Submission time Handle Problem Language Result Execution time Memory
647661 2022-10-03T13:58:52 Z ToroTN Flood (IOI07_flood) C++14
0 / 100
41 ms 65536 KB
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define X first
#define Y second
int n,x[100141],y[100141],xx[400141],yy[400141],dx[]={1,1,3,3},dy[]={1,3,1,3};
int m,wall1,wall2,a1,b1,a2,b2,l,r,st=0,d[400141],u,num=0,comp=1;
vector<pair<int,int> > row[2000141],column[2000141];
vector<pair<int,int> > g[400141];
vector<int> empbrick;
queue<int> q;
map<pair<int,int>,int> mp,mp2;
set<int> s;
set<int> debug;
set<pair<int,int> > uaytaq;
priority_queue<pair<int,int> > pq;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&x[i],&y[i]);
        for(int j=0;j<4;j++)
        {
            uaytaq.insert({2*x[i]+dx[j],2*y[i]+dy[j]});
        }
    }
    for(auto [l,r]:uaytaq)
    {
        ++num;
        xx[num]=l;
        yy[num]=r;
    }
    for(int i=1;i<=uaytaq.size();i++)
    {
        d[i]=1e9;
        //printf("uaytaq=%d %d\n",xx[i],yy[i]);
        mp[{xx[i],yy[i]}]=i;
        row[xx[i]].pb({yy[i],i});
        column[yy[i]].pb({xx[i],i});
    }
    for(int i=1;i<=2000100;i++)
    {
        sort(row[i].begin(),row[i].end());
        sort(column[i].begin(),column[i].end());
    }
    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);
        if(b1>b2)swap(b1,b2);
        if(a1<a2)
        {
            mp2[{mp[{2*a1+3,2*b1+1}],mp[{2*a1+3,2*b1+3}]}]=i;
            mp2[{mp[{2*a2+1,2*b2+1}],mp[{2*a2+1,2*b2+3}]}]=i;
        }
        if(b1<b2)
        {
            mp2[{mp[{2*a1+1,2*b1+3}],mp[{2*a1+3,2*b1+3}]}]=i;
            mp2[{mp[{2*a2+1,2*b2+1}],mp[{2*a2+3,2*b2+1}]}]=i;
        }
    }
    for(int i=0;i<=2000100;i++)
    {
        for(int j=0;j<(int)row[i].size()-1;j++)
        {
            l=row[i][j].Y;
            r=row[i][j+1].Y;
            if(st==0)
            {
                st=1;
                d[l]=0;
                q.push(l);
            }
            g[l].pb({r,max(mp2[{l,r}],mp2[{r,l}])});
            g[r].pb({l,max(mp2[{l,r}],mp2[{r,l}])});
        }
        for(int j=0;j<(int)column[i].size()-1;j++)
        {
            l=column[i][j].Y;
            r=column[i][j+1].Y;
            g[l].pb({r,max(mp2[{l,r}],mp2[{r,l}])});
            g[r].pb({l,max(mp2[{l,r}],mp2[{r,l}])});
        }
    }
    for(int i=0;;i++)
    {
        empbrick.clear();
        if(comp==uaytaq.size())break;
        while(!q.empty())
        {
            u=q.front();
            //printf("%d\n",u);
            empbrick.pb(u);
            q.pop();
            for(auto [node,w]:g[u])
            {
                if(w==0&&d[node]==1e9)
                {
                    d[node]=d[u];
                    ++comp;
                    q.push(node);
                }
            }
        }
        //printf("comp=%d\n",comp);
        //printf("%d\n",i);
        for(auto ken:empbrick)
        {
            //printf("%d ",ken);
            for(auto [node,w]:g[ken])
            {
                if(d[node]>d[ken]&&w>0)
                {
                    if(d[node]==1e9)++comp;
                    d[node]=d[ken]+1;
                    s.erase(w);
                    q.push(node);
                    if(comp==uaytaq.size())break;
                }
            }
        }
        //printf("\n");
    }
    printf("%d\n",s.size());
    for(auto it:s)
    {
        printf("%d\n",it);
    }
    printf("\n");
}

Compilation message

flood.cpp: In function 'int main()':
flood.cpp:28:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |     for(auto [l,r]:uaytaq)
      |              ^
flood.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for(int i=1;i<=uaytaq.size();i++)
      |                 ~^~~~~~~~~~~~~~~
flood.cpp:95:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |         if(comp==uaytaq.size())break;
      |            ~~~~^~~~~~~~~~~~~~~
flood.cpp:102:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  102 |             for(auto [node,w]:g[u])
      |                      ^
flood.cpp:117:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  117 |             for(auto [node,w]:g[ken])
      |                      ^
flood.cpp:125:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  125 |                     if(comp==uaytaq.size())break;
      |                        ~~~~^~~~~~~~~~~~~~~
flood.cpp:131:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
  131 |     printf("%d\n",s.size());
      |             ~^    ~~~~~~~~
      |              |          |
      |              int        std::set<int>::size_type {aka long unsigned int}
      |             %ld
flood.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |     scanf("%d",&n);
      |     ~~~~~^~~~~~~~~
flood.cpp:22:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         scanf("%d%d",&x[i],&y[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~
flood.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |     scanf("%d",&m);
      |     ~~~~~^~~~~~~~~
flood.cpp:51:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         scanf("%d%d",&wall1,&wall2);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 31 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 41 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 39 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 34 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 30 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 35 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 32 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 33 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 38 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -