# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
647683 |
2022-10-03T15:32:20 Z |
ToroTN |
Flood (IOI07_flood) |
C++14 |
|
11 ms |
5076 KB |
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define X first
#define Y second
int n,x[1005],y[1005],xx[4005],yy[4005],dx[]={1,1,3,3},dy[]={1,3,1,3};
int m,wall1,wall2,a1,b1,a2,b2,l,r,st=0,d[4005],u,num=0,comp=1;
vector<pair<int,int> > row[20005],column[20005];
vector<pair<int,int> > g[4005];
vector<int> empbrick;
queue<int> q;
map<pair<int,int>,int> mp,mp2;
set<int> s;
set<pair<int,int> > uaytaq;
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;
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();
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);
}
}
}
for(auto ken:empbrick)
{
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("%d\n",s.size());
for(auto it:s)
{
printf("%d\n",it);
}
printf("\n");
}
Compilation message
flood.cpp: In function 'int main()':
flood.cpp:26:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | for(auto [l,r]:uaytaq)
| ^
flood.cpp:32: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]
32 | for(int i=1;i<=uaytaq.size();i++)
| ~^~~~~~~~~~~~~~~
flood.cpp:92: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]
92 | if(comp==uaytaq.size())break;
| ~~~~^~~~~~~~~~~~~~~
flood.cpp:98:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
98 | for(auto [node,w]:g[u])
| ^
flood.cpp:110:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
110 | for(auto [node,w]:g[ken])
| ^
flood.cpp:118: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]
118 | if(comp==uaytaq.size())break;
| ~~~~^~~~~~~~~~~~~~~
flood.cpp:123:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
123 | printf("%d\n",s.size());
| ~^ ~~~~~~~~
| | |
| int std::set<int>::size_type {aka long unsigned int}
| %ld
flood.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
flood.cpp:20:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
20 | scanf("%d%d",&x[i],&y[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
flood.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d",&m);
| ~~~~~^~~~~~~~~
flood.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
48 | scanf("%d%d",&wall1,&wall2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2516 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2516 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2644 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2644 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
2616 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2536 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2644 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
2632 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
2636 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
3668 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
4428 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
5064 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
11 ms |
5072 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
10 ms |
5076 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |