#include "artclass.h"
#include<bits/stdc++.h>
using namespace std;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};
int H,W;
int R[505][505],G[505][505],B[505][505];
bool is_green()
{
int dif=0;
for(int i=1;i<=H;i++)
{
for(int j=1;j<=W;j++)
{
dif += G[i][j];
dif -= R[i][j] + B[i][j];
}
}
if(dif >= H*W * (0))
return 1;
return 0;
}
bool visited[505][505];
bool similar(int ax, int ay, int bx, int by)
{
if(abs(R[ax][ay]-R[bx][by]) + abs(G[ax][ay]-G[bx][by]) + abs(B[ax][ay]-B[bx][by]) <= 15)
return 1;
return 0;
}
void dfs(int x, int y)
{
visited[x][y]=1;
for(int v=0;v<4;v++)
{
int newx = x+dx[v], newy = y+dy[v];
if(newx>=1 && newx<=H && newy>=1 && newy<=W && !visited[newx][newy] && similar(x,y,newx,newy))
dfs(newx,newy);
}
}
int nr_zones()
{
int cnt=0;
for(int i=1;i<=H;i++)
{
for(int j=1;j<=W;j++)
{
if(!visited[i][j])
{
cnt++;
dfs(i,j);
}
}
}
return cnt;
}
int style(int cit_H, int cit_W, int cit_R[500][500], int cit_G[500][500], int cit_B[500][500])
{
H = cit_H;
W = cit_W;
for(int i=1;i<=H;i++)
{
for(int j=1;j<=W;j++)
{
R[i][j] = cit_R[i-1][j-1];
G[i][j] = cit_G[i-1][j-1];
B[i][j] = cit_B[i-1][j-1];
}
}
if(is_green())
return 2;
int nrz = nr_zones();
if(nrz <= 3000)
return 4;
if(nrz >= 50000)
return 3;
return 1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |