#include "artclass.h"
#include<bits/stdc++.h>
using namespace std;
const int N = 510;
int componentes;
int mark[N][N];
int h, w;
int r[N][N], g[N][N], b[N][N];
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
bool check(int i, int j){
if(i < 0 or i >= h or j < 0 or j >= w) return false;
return true;
}
bool diff(int a, int bb, int c, int d){
//cout << max({abs(r[a][bb]-r[c][d]), abs(g[a][bb]-g[c][d]), abs(b[a][bb]-b[c][d])}) << endl;
if(abs(r[a][bb]-r[c][d]) + abs(g[a][bb]-g[c][d])+ abs(b[a][bb]-b[c][d]) >= 60) return false;
return true;
}
void dfs(int i, int j){
if(!check(i, j)) return;
if(mark[i][j]) return;
mark[i][j] = 1;
for(int t = 0;t < 4;t++){
if(check(i+dx[t], j+dy[t])){
if(diff(i, j, i+dx[t], j+dx[t])) dfs(i+dx[t], j+dx[t]);
}
}
return;
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
h = H;
w = W;
int qtdbrancos = 0, qtdpretos = 0;
int diff = 0;
for(int i = 0;i < H;i++){
for(int j = 0;j < W;j++){
r[i][j] = R[i][j];
g[i][j] = G[i][j];
b[i][j] = B[i][j];
if(r[i][j]+g[i][j]+b[i][j] > 600) qtdbrancos++;
if(r[i][j]+g[i][j]+b[i][j] < 100) qtdpretos++;
if(j > 0){
int t = abs(r[i][j] - r[i][j-1])+abs(g[i][j] - g[i][j-1])+abs(b[i][j] - b[i][j-1]);
if(t > 100) diff++;
}
}
}
for(int i = 0;i < H;i++){
for(int j = 0;j < W;j++){
if(!mark[i][j]) {
dfs(i, j);
componentes++;
}
}
}
//cout << diff << ' ';
if(diff > 5e4) return 3;
else if(qtdbrancos > 5e4) return 1;
else if(componentes < 5000) return 4;
return 2;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |