Submission #1990295
Source Code Expand
#include <iostream>
#include <set>
#include <queue>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
int w;
int h;
int W;
int H;
int n;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
vector<int> xs,ys,xe,ye;
vector<int> X,Y;
int imos[3000][3000];
int main()
{
cin >> w >> h;
cin >> n;
xs.resize(n);
ys.resize(n);
xe.resize(n);
ye.resize(n);
for(int i = 0;i < n;i++)
{
int x1,y1,x2,y2;
cin >> x1 >> y1 >> x2 >> y2;
xs[i] = x1;
ys[i] = y1;
xe[i] = x2;
ye[i] = y2;
X.push_back(x1);
X.push_back(x2);
Y.push_back(y1);
Y.push_back(y2);
}
X.push_back(0);
Y.push_back(0);
X.push_back(w);
Y.push_back(h);
sort(X.begin(),X.end());
sort(Y.begin(),Y.end());
X.erase(unique(X.begin(),X.end()),X.end());
Y.erase(unique(Y.begin(),Y.end()),Y.end());
W = X.size() - 2;
H = Y.size() - 2;
for(int i = 0;i < n;i++)
{
int x1 = lower_bound(X.begin(),X.end(),xs[i]) - X.begin();
int x2 = lower_bound(X.begin(),X.end(),xe[i]) - X.begin();
int y1 = lower_bound(Y.begin(),Y.end(),ys[i]) - Y.begin();
int y2 = lower_bound(Y.begin(),Y.end(),ye[i]) - Y.begin();
imos[x1][y1]++;
imos[x2][y2]++;
imos[x1][y2]--;
imos[x2][y1]--;
}
for(int y = 0;y <= H;y++)
for(int x = 1;x <= W;x++)
imos[x][y] += imos[x - 1][y];
for(int x = 0;x <= W;x++)
for(int y = 1;y <= H;y++)
imos[x][y] += imos[x][y - 1];
int result = 0;
for(int x = 0;x <= W;x++)
{
for(int y= 0;y <= H;y++)
{
if(imos[x][y] == 0)
{
queue<P> q;
result++;
q.push(P(x,y));
while(!q.empty())
{
int xi = q.front().first;
int yi = q.front().second;
q.pop();
if(imos[xi][yi] == 1) continue;
imos[xi][yi] = 1;
for(int i = 0;i < 4;i++)
{
int nx = xi + dx[i];
int ny = yi + dy[i];
if(0 <= nx && nx <= W && 0 <= ny && ny <= H && imos[nx][ny] == 0)
{
q.push(P(nx,ny));
}
}
}
}
}
}
cout << result << endl;
return 0;
}
Submission Info
Submission Time |
|
Task |
E - ペンキの色 |
User |
niuez |
Language |
C++14 (GCC 5.4.1) |
Score |
20 |
Code Size |
2128 Byte |
Status |
AC |
Exec Time |
93 ms |
Memory |
24832 KB |
Judge Result
Set Name |
set01 |
set02 |
set03 |
set04 |
set05 |
set06 |
set07 |
set08 |
set09 |
set10 |
set11 |
set12 |
set13 |
set14 |
set15 |
set16 |
set17 |
set18 |
set19 |
set20 |
Score / Max Score |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
1 / 1 |
Status |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Set Name |
Test Cases |
set01 |
data1 |
set02 |
data2 |
set03 |
data3 |
set04 |
data4 |
set05 |
data5 |
set06 |
data6 |
set07 |
data7 |
set08 |
data8 |
set09 |
data9 |
set10 |
data10 |
set11 |
data11 |
set12 |
data12 |
set13 |
data13 |
set14 |
data14 |
set15 |
data15 |
set16 |
data16 |
set17 |
data17 |
set18 |
data18 |
set19 |
data19 |
set20 |
data20 |
Case Name |
Status |
Exec Time |
Memory |
data1 |
AC |
1 ms |
256 KB |
data10 |
AC |
10 ms |
7424 KB |
data11 |
AC |
31 ms |
24832 KB |
data12 |
AC |
56 ms |
24832 KB |
data13 |
AC |
84 ms |
24832 KB |
data14 |
AC |
31 ms |
11904 KB |
data15 |
AC |
34 ms |
11904 KB |
data16 |
AC |
31 ms |
24832 KB |
data17 |
AC |
26 ms |
18304 KB |
data18 |
AC |
73 ms |
20480 KB |
data19 |
AC |
93 ms |
24832 KB |
data2 |
AC |
1 ms |
256 KB |
data20 |
AC |
13 ms |
11904 KB |
data3 |
AC |
1 ms |
256 KB |
data4 |
AC |
1 ms |
256 KB |
data5 |
AC |
1 ms |
256 KB |
data6 |
AC |
1 ms |
256 KB |
data7 |
AC |
3 ms |
3072 KB |
data8 |
AC |
3 ms |
3072 KB |
data9 |
AC |
9 ms |
7424 KB |