#include <bits/stdc++.h>
#include "artclass.h"
using namespace std;
const int N = 500;
const int ISSAME_THRESHOLD = 30;
const int ISGREEN_THRESHOLD = 30;
const bool IS_MAX = true;
const int GREEN = 31;
const int CNTMIN = 20;
const int CNTMAX = 800;
const int K = 8;
const int xd[K] = {-1, -1, 0, 1, 1, 1, 0, -1};
const int yd[K] = {0, 1, 1, 1, 0, -1, -1, -1};
int h, w, greencnt;
array<int, 3> color[N][N];
struct DSU{
pair<int, int> par[N][N];
int setsize[N][N];
int setcnt;
void reset(int n, int m){
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
par[i][j] = {i, j};
setsize[i][j] = 1;
}
}
setcnt = n * m;
}
pair<int, int> setfind(pair<int, int> a){
if(par[a.first][a.second] == a) return a;
else return par[a.first][a.second] = setfind(par[a.first][a.second]);
}
void setunion(pair<int, int> a, pair<int, int> b){
a = setfind(a), b = setfind(b);
if(a != b){
if(setsize[b.first][b.second] > setsize[a.first][a.second]) swap(a, b);
par[b.first][b.second] = a;
setsize[a.first][a.second] += setsize[b.first][b.second];
setcnt--;
}
}
};
DSU dsu;
bool issame(array<int, 3> a, array<int, 3> b){
int diff;
if(IS_MAX) diff = max({abs(a[0] - b[0]), abs(a[1] - b[1]), abs(a[2] - b[2])});
else diff = abs(a[0] - b[0]) + abs(a[1] - b[1]) + abs(a[2] - b[2]);
return diff <= ISSAME_THRESHOLD;
}
bool isgreen(array<int, 3> a){
// return (a[1] - max(a[0], a[2])) >= ISGREEN_THRESHOLD;
return (a[1] - a[2]) >= ISGREEN_THRESHOLD && ((a[1] - a[0] >= ISGREEN_THRESHOLD) || (a[0] - a[1] <= ISGREEN_THRESHOLD));
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]){
h = H, w = W;
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
color[i][j] = {R[i][j], G[i][j], B[i][j]};
}
}
dsu.reset(h, w);
for(int i = 0; i < h; i++){
for(int j = 0; j < w; j++){
for(int k = 0; k < K; k++){
int x = i + xd[k], y = j + yd[k];
if(x >= 0 && x < h && y >= 0 && y < w && issame(color[i][j], color[x][y])){
dsu.setunion({i, j}, {x, y});
}
}
greencnt += isgreen(color[i][j]);
}
}
// cout << "Color Count: " << dsu.setcnt << " " << "Green Count: " << greencnt << " " << "Green Percent: " << greencnt * 100 / (h * w) <<"\n";
// cout << dsu.setcnt << "\n";
if(greencnt * 100 / (h * w) >= GREEN) return 2;
else if(dsu.setcnt <= CNTMIN) return 4;
else if(dsu.setcnt <= CNTMAX) return 1;
else return 3;
return -1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
59 ms |
9020 KB |
Output is correct |
2 |
Correct |
68 ms |
7252 KB |
Output is correct |
3 |
Correct |
74 ms |
8032 KB |
Output is correct |
4 |
Correct |
84 ms |
9032 KB |
Output is correct |
5 |
Correct |
80 ms |
8996 KB |
Output is correct |
6 |
Incorrect |
87 ms |
9060 KB |
Output isn't correct |
7 |
Incorrect |
78 ms |
8268 KB |
Output isn't correct |
8 |
Correct |
70 ms |
9000 KB |
Output is correct |
9 |
Correct |
83 ms |
9084 KB |
Output is correct |
10 |
Correct |
47 ms |
5948 KB |
Output is correct |
11 |
Correct |
59 ms |
9036 KB |
Output is correct |
12 |
Correct |
60 ms |
9036 KB |
Output is correct |
13 |
Incorrect |
70 ms |
9036 KB |
Output isn't correct |
14 |
Incorrect |
81 ms |
8908 KB |
Output isn't correct |
15 |
Correct |
70 ms |
9088 KB |
Output is correct |
16 |
Incorrect |
77 ms |
9028 KB |
Output isn't correct |
17 |
Correct |
54 ms |
9064 KB |
Output is correct |
18 |
Correct |
69 ms |
7676 KB |
Output is correct |
19 |
Correct |
36 ms |
5076 KB |
Output is correct |
20 |
Correct |
72 ms |
9032 KB |
Output is correct |
21 |
Incorrect |
75 ms |
9088 KB |
Output isn't correct |
22 |
Correct |
70 ms |
9084 KB |
Output is correct |
23 |
Correct |
69 ms |
7732 KB |
Output is correct |
24 |
Correct |
22 ms |
8856 KB |
Output is correct |
25 |
Correct |
57 ms |
9088 KB |
Output is correct |
26 |
Correct |
46 ms |
5712 KB |
Output is correct |
27 |
Correct |
71 ms |
7876 KB |
Output is correct |
28 |
Incorrect |
67 ms |
7672 KB |
Output isn't correct |
29 |
Correct |
89 ms |
8996 KB |
Output is correct |
30 |
Correct |
65 ms |
7488 KB |
Output is correct |
31 |
Correct |
78 ms |
8616 KB |
Output is correct |
32 |
Correct |
76 ms |
9052 KB |
Output is correct |
33 |
Incorrect |
71 ms |
9084 KB |
Output isn't correct |
34 |
Correct |
35 ms |
5032 KB |
Output is correct |
35 |
Correct |
71 ms |
9052 KB |
Output is correct |
36 |
Incorrect |
55 ms |
6776 KB |
Output isn't correct |
37 |
Correct |
83 ms |
8964 KB |
Output is correct |
38 |
Incorrect |
43 ms |
5624 KB |
Output isn't correct |
39 |
Correct |
69 ms |
9084 KB |
Output is correct |
40 |
Correct |
71 ms |
9068 KB |
Output is correct |
41 |
Correct |
71 ms |
7924 KB |
Output is correct |
42 |
Correct |
73 ms |
7820 KB |
Output is correct |
43 |
Correct |
65 ms |
9080 KB |
Output is correct |
44 |
Correct |
102 ms |
9036 KB |
Output is correct |
45 |
Incorrect |
68 ms |
7536 KB |
Output isn't correct |
46 |
Correct |
57 ms |
9036 KB |
Output is correct |
47 |
Correct |
78 ms |
7488 KB |
Output is correct |
48 |
Correct |
18 ms |
3540 KB |
Output is correct |
49 |
Correct |
86 ms |
9056 KB |
Output is correct |
50 |
Correct |
72 ms |
7596 KB |
Output is correct |
51 |
Correct |
71 ms |
7880 KB |
Output is correct |
52 |
Correct |
85 ms |
9080 KB |
Output is correct |
53 |
Correct |
53 ms |
9080 KB |
Output is correct |
54 |
Correct |
73 ms |
8000 KB |
Output is correct |
55 |
Correct |
68 ms |
9036 KB |
Output is correct |
56 |
Correct |
65 ms |
7504 KB |
Output is correct |
57 |
Correct |
62 ms |
6596 KB |
Output is correct |
58 |
Correct |
41 ms |
5740 KB |
Output is correct |
59 |
Correct |
68 ms |
9036 KB |
Output is correct |
60 |
Incorrect |
68 ms |
9084 KB |
Output isn't correct |
61 |
Incorrect |
82 ms |
9064 KB |
Output isn't correct |
62 |
Correct |
74 ms |
7936 KB |
Output is correct |
63 |
Correct |
91 ms |
9092 KB |
Output is correct |
64 |
Correct |
79 ms |
7956 KB |
Output is correct |
65 |
Correct |
69 ms |
9064 KB |
Output is correct |
66 |
Correct |
53 ms |
6604 KB |
Output is correct |
67 |
Correct |
46 ms |
9056 KB |
Output is correct |
68 |
Correct |
59 ms |
9044 KB |
Output is correct |
69 |
Correct |
62 ms |
7232 KB |
Output is correct |
70 |
Correct |
73 ms |
7984 KB |
Output is correct |
71 |
Incorrect |
76 ms |
8284 KB |
Output isn't correct |
72 |
Correct |
65 ms |
9084 KB |
Output is correct |
73 |
Correct |
84 ms |
8976 KB |
Output is correct |
74 |
Correct |
62 ms |
8996 KB |
Output is correct |
75 |
Correct |
95 ms |
9152 KB |
Output is correct |
76 |
Incorrect |
82 ms |
9072 KB |
Output isn't correct |
77 |
Correct |
65 ms |
7392 KB |
Output is correct |
78 |
Correct |
67 ms |
9088 KB |
Output is correct |
79 |
Correct |
69 ms |
9080 KB |
Output is correct |
80 |
Correct |
51 ms |
6304 KB |
Output is correct |
81 |
Incorrect |
73 ms |
8988 KB |
Output isn't correct |
82 |
Correct |
73 ms |
9036 KB |
Output is correct |
83 |
Correct |
81 ms |
7736 KB |
Output is correct |
84 |
Correct |
70 ms |
7884 KB |
Output is correct |
85 |
Correct |
48 ms |
5796 KB |
Output is correct |
86 |
Correct |
52 ms |
8980 KB |
Output is correct |
87 |
Incorrect |
57 ms |
9072 KB |
Output isn't correct |
88 |
Correct |
57 ms |
9092 KB |
Output is correct |
89 |
Correct |
34 ms |
4984 KB |
Output is correct |
90 |
Correct |
85 ms |
9036 KB |
Output is correct |
91 |
Correct |
65 ms |
9048 KB |
Output is correct |
92 |
Correct |
67 ms |
9004 KB |
Output is correct |
93 |
Correct |
42 ms |
9084 KB |
Output is correct |
94 |
Correct |
64 ms |
7372 KB |
Output is correct |
95 |
Correct |
72 ms |
9084 KB |
Output is correct |
96 |
Correct |
80 ms |
7224 KB |
Output is correct |
97 |
Incorrect |
54 ms |
9036 KB |
Output isn't correct |
98 |
Correct |
73 ms |
7760 KB |
Output is correct |
99 |
Incorrect |
63 ms |
7388 KB |
Output isn't correct |
100 |
Correct |
88 ms |
8972 KB |
Output is correct |
101 |
Correct |
53 ms |
6392 KB |
Output is correct |
102 |
Incorrect |
68 ms |
9084 KB |
Output isn't correct |