# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
651732 | LucaGreg | Art Class (IOI13_artclass) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#include "artclass.h"
int l, c;
int min_sz_comp;
int min_bigcomp;
int min_bigcomp_group14;
int min_qtd_green;
int min_dif;
int min_colors_sum;
int min_qtd_greencomp;
int min_sz_greencomp;
struct pixel{
int red, green, blue;
pixel(int r = 0, int g = 0, int b = 0){
red = r;
green = g;
blue = b;
}
bool operator == (pixel b){
int red_dif = abs((*this).red - b.red);
int green_dif = abs((*this).green - b.green);
int blue_dif = abs((*this).blue - b.blue);
return (red_dif<=min_dif && green_dif<=min_dif && blue_dif<=min_dif);
}
bool isGreen(){
int sum = red + green + blue;
return ((green>red && green>blue) && sum<min_colors_sum);
}
};
pixel image[510][510];
bool green_image[510][510];
int marc[510][510];
int dl[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};
int find_comp(int li, int ci){
int qtd_pixel = 1;
marc[li][ci] = 1;
for(int i=0;i<4;i++){
int vizl = li + dl[i];
int vizc = ci + dc[i];
if(vizl<0 || vizl>l-1) continue;
if(vizc<0 || vizc>c-1) continue;
if(marc[vizl][vizc] == 1) continue;
if(image[vizl][vizc] == image[li][ci]) qtd_pixel += find_comp(vizl, vizc);
}
return qtd_pixel;
}
pair<int, int> find_bigcomp(){
memset(marc, 0, sizeof(marc));
int qtd_bigcomp_ = 0;
int qtd_comp_ = 0;
for(int i=0;i<l;i++){
for(int j=0;j<c;j++){
if(marc[i][j] == 0){
int sz_comp = find_comp(i, j);
qtd_comp_++;
if(sz_comp>min_sz_comp) qtd_bigcomp_++;
}
}
}
return {qtd_bigcomp_, qtd_comp_};
}
int do_green_image(){
int qtd_green_ = 0;
for(int i=0;i<l;i++){
for(int j=0;j<c;j++){
green_image[i][j] = image[i][j].isGreen();
qtd_green_ += green_image[i][j];
}
}
return qtd_green_;
}
int marc_greencomp(int li, int ci){
int sz_greencomp = 1;
marc[li][ci] = 1;
for(int i=0;i<4;i++){
int vizl = li + dl[i];
int vizc = ci + dc[i];
if(vizl<0 || vizl>l-1) continue;
if(vizc<0 || vizc>c-1) continue;
if(marc[vizl][vizc] == 1) continue;
if(green_image[vizl][vizc]) sz_greencomp += marc_greencomp(vizl, vizc);
}
return sz_greencomp;
}
int find_greencomp(){
memset(marc, 0, sizeof(marc));
int max_sz_greencomp = 0;
int qtd_greencomp_ = 0;
for(int i=0;i<l;i++){
for(int j=0;j<c;j++){
if(marc[i][j] == 0 && green_image[i][j]){
max_sz_greencomp = max(max_sz_greencomp, marc_greencomp(i, j));
qtd_greencomp_++;
}
}
}
return max_sz_greencomp;
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
l = H;
c = W;
min_sz_comp = ((l*c)/15);
min_bigcomp = 2;
min_bigcomp_group14 = 6;
//min_qtd_green = ((l*c)/4);
min_dif = 5;
min_colors_sum = 300;
//min_qtd_greencomp = 8;
min_sz_greencomp = ((l*c)/15);
for(int i=0;i<l;i++){
for(int j=0;j<c;j++){
image[i][j] = pixel(R[i][j], G[i][j], B[i][j]);
}
}
pair<int, int> aux = find_bigcomp();
int qtd_bigcomp = aux.first;
int qtd_comp = aux.second;
if(qtd_bigcomp>min_bigcomp){
if(qtd_bigcomp<min_bigcomp_group14) return 4;
else return 1;
}