#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;
}
int qtd_green = do_green_image();
/*if(qtd_green<min_qtd_green){
return 3;
}*/
int max_sz_greencomp = find_greencomp();
if(max_sz_greencomp>min_sz_greencomp) return 2;
else return 3;
/*if(qtd_greencomp<min_qtd_greencomp) return 2;
else return 3;*/
}
Compilation message
artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:134:9: warning: unused variable 'qtd_comp' [-Wunused-variable]
134 | int qtd_comp = aux.second;
| ^~~~~~~~
artclass.cpp:142:9: warning: unused variable 'qtd_green' [-Wunused-variable]
142 | int qtd_green = do_green_image();
| ^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
53 ms |
8076 KB |
Output isn't correct |
2 |
Correct |
36 ms |
7496 KB |
Output is correct |
3 |
Incorrect |
52 ms |
14352 KB |
Output isn't correct |
4 |
Correct |
48 ms |
10960 KB |
Output is correct |
5 |
Incorrect |
64 ms |
11580 KB |
Output isn't correct |
6 |
Correct |
55 ms |
11980 KB |
Output is correct |
7 |
Correct |
45 ms |
6680 KB |
Output is correct |
8 |
Incorrect |
70 ms |
8244 KB |
Output isn't correct |
9 |
Correct |
43 ms |
7544 KB |
Output is correct |
10 |
Incorrect |
57 ms |
7544 KB |
Output isn't correct |
11 |
Correct |
54 ms |
8584 KB |
Output is correct |
12 |
Correct |
54 ms |
7640 KB |
Output is correct |
13 |
Incorrect |
37 ms |
8516 KB |
Output isn't correct |
14 |
Correct |
52 ms |
11840 KB |
Output is correct |
15 |
Incorrect |
63 ms |
8152 KB |
Output isn't correct |
16 |
Incorrect |
59 ms |
8876 KB |
Output isn't correct |
17 |
Correct |
37 ms |
6220 KB |
Output is correct |
18 |
Correct |
29 ms |
5968 KB |
Output is correct |
19 |
Incorrect |
34 ms |
9568 KB |
Output isn't correct |
20 |
Correct |
45 ms |
7504 KB |
Output is correct |
21 |
Correct |
52 ms |
7116 KB |
Output is correct |
22 |
Correct |
47 ms |
7012 KB |
Output is correct |
23 |
Correct |
59 ms |
14040 KB |
Output is correct |
24 |
Incorrect |
66 ms |
8568 KB |
Output isn't correct |
25 |
Incorrect |
65 ms |
10960 KB |
Output isn't correct |
26 |
Correct |
42 ms |
6628 KB |
Output is correct |
27 |
Incorrect |
50 ms |
7196 KB |
Output isn't correct |
28 |
Correct |
29 ms |
9812 KB |
Output is correct |
29 |
Incorrect |
63 ms |
22280 KB |
Output isn't correct |
30 |
Incorrect |
68 ms |
18340 KB |
Output isn't correct |
31 |
Incorrect |
54 ms |
14780 KB |
Output isn't correct |
32 |
Incorrect |
47 ms |
11372 KB |
Output isn't correct |
33 |
Correct |
17 ms |
9332 KB |
Output is correct |
34 |
Incorrect |
48 ms |
7120 KB |
Output isn't correct |
35 |
Incorrect |
49 ms |
15148 KB |
Output isn't correct |
36 |
Incorrect |
52 ms |
21492 KB |
Output isn't correct |
37 |
Incorrect |
49 ms |
10912 KB |
Output isn't correct |
38 |
Correct |
59 ms |
8264 KB |
Output is correct |
39 |
Correct |
48 ms |
6912 KB |
Output is correct |
40 |
Incorrect |
46 ms |
13728 KB |
Output isn't correct |
41 |
Incorrect |
48 ms |
9036 KB |
Output isn't correct |
42 |
Incorrect |
41 ms |
13756 KB |
Output isn't correct |
43 |
Correct |
49 ms |
7292 KB |
Output is correct |
44 |
Correct |
46 ms |
7304 KB |
Output is correct |
45 |
Correct |
72 ms |
11888 KB |
Output is correct |
46 |
Correct |
59 ms |
11884 KB |
Output is correct |
47 |
Correct |
39 ms |
10196 KB |
Output is correct |
48 |
Correct |
48 ms |
7552 KB |
Output is correct |
49 |
Correct |
51 ms |
7484 KB |
Output is correct |
50 |
Correct |
49 ms |
6900 KB |
Output is correct |
51 |
Incorrect |
60 ms |
9600 KB |
Output isn't correct |
52 |
Correct |
51 ms |
9124 KB |
Output is correct |
53 |
Incorrect |
61 ms |
11296 KB |
Output isn't correct |
54 |
Incorrect |
52 ms |
7816 KB |
Output isn't correct |
55 |
Incorrect |
61 ms |
7612 KB |
Output isn't correct |
56 |
Correct |
44 ms |
6656 KB |
Output is correct |
57 |
Incorrect |
63 ms |
16424 KB |
Output isn't correct |
58 |
Incorrect |
56 ms |
19924 KB |
Output isn't correct |
59 |
Incorrect |
45 ms |
13892 KB |
Output isn't correct |
60 |
Correct |
31 ms |
5948 KB |
Output is correct |
61 |
Correct |
32 ms |
7884 KB |
Output is correct |
62 |
Correct |
38 ms |
6412 KB |
Output is correct |
63 |
Correct |
50 ms |
7540 KB |
Output is correct |
64 |
Incorrect |
39 ms |
6900 KB |
Output isn't correct |
65 |
Incorrect |
52 ms |
7244 KB |
Output isn't correct |
66 |
Correct |
58 ms |
10096 KB |
Output is correct |
67 |
Incorrect |
64 ms |
11340 KB |
Output isn't correct |
68 |
Correct |
47 ms |
10572 KB |
Output is correct |
69 |
Incorrect |
53 ms |
7324 KB |
Output isn't correct |
70 |
Correct |
54 ms |
11708 KB |
Output is correct |
71 |
Correct |
53 ms |
8556 KB |
Output is correct |
72 |
Correct |
27 ms |
5688 KB |
Output is correct |
73 |
Incorrect |
48 ms |
7024 KB |
Output isn't correct |
74 |
Incorrect |
46 ms |
7032 KB |
Output isn't correct |
75 |
Correct |
57 ms |
10964 KB |
Output is correct |
76 |
Correct |
27 ms |
5588 KB |
Output is correct |
77 |
Correct |
32 ms |
6012 KB |
Output is correct |
78 |
Correct |
38 ms |
7444 KB |
Output is correct |
79 |
Correct |
52 ms |
8376 KB |
Output is correct |
80 |
Incorrect |
48 ms |
17984 KB |
Output isn't correct |
81 |
Incorrect |
55 ms |
18236 KB |
Output isn't correct |
82 |
Correct |
36 ms |
6220 KB |
Output is correct |
83 |
Incorrect |
60 ms |
12364 KB |
Output isn't correct |
84 |
Incorrect |
36 ms |
6988 KB |
Output isn't correct |
85 |
Correct |
48 ms |
10956 KB |
Output is correct |
86 |
Correct |
49 ms |
6760 KB |
Output is correct |
87 |
Correct |
47 ms |
11940 KB |
Output is correct |
88 |
Correct |
14 ms |
4984 KB |
Output is correct |
89 |
Incorrect |
51 ms |
7808 KB |
Output isn't correct |
90 |
Correct |
42 ms |
8568 KB |
Output is correct |
91 |
Incorrect |
58 ms |
11472 KB |
Output isn't correct |
92 |
Incorrect |
48 ms |
7072 KB |
Output isn't correct |
93 |
Correct |
45 ms |
7480 KB |
Output is correct |
94 |
Correct |
43 ms |
7576 KB |
Output is correct |
95 |
Correct |
33 ms |
5700 KB |
Output is correct |
96 |
Correct |
61 ms |
14704 KB |
Output is correct |
97 |
Incorrect |
51 ms |
8020 KB |
Output isn't correct |
98 |
Correct |
46 ms |
11812 KB |
Output is correct |
99 |
Incorrect |
45 ms |
7064 KB |
Output isn't correct |
100 |
Correct |
58 ms |
8912 KB |
Output is correct |
101 |
Correct |
53 ms |
12108 KB |
Output is correct |
102 |
Correct |
62 ms |
10528 KB |
Output is correct |