#ifndef ONLINE_JUDGE
#include "artclass.h"
#endif
#include <bits/stdc++.h>
struct pixel {
double r, g, b;
double h, s, l;
pixel() {
r = g = b = h = s = l = 0.0;
}
pixel(int _r, int _g, int _b) {
r = _r / 255.0;
g = _g / 255.0;
b = _b / 255.0;
auto xmax = std::max({r, g, b});
auto xmin = std::min({r, g, b});
auto c = xmax - xmin;
l = (xmax + xmin) / 2;
if (xmax == 0) {
s = 0;
} else {
s = c / xmax;
}
if (c == 0.0) {
h = 0;
} else if (xmax == r) {
h = 60.0 * (fmod(60.0 + ((g - b) / c), 6.0));
} else if (xmax == g) {
h = 60.0 * ((b - r) / c + 2.0);
} else if (xmax == b) {
h = 60.0 * ((r - g) / c + 4.0);
} else {
assert(false);
}
}
};
bool green(int r, int g, int b) {
return (g > 100 && r < 100 && b < 100) || (g > 50 && r < 50 && b < 50);
}
double dist(pixel _a, pixel _b) {
auto r = _a.r - _b.r;
auto g = _a.g - _b.g;
auto b = _a.b - _b.b;
return std::sqrt(r * r + g * g + b * b);
}
double noise(std::vector<pixel> pixels) {
double res = 0;
for (int i = 0; i < pixels.size(); ++i) {
for (int j = i + 1; j < pixels.size(); ++j) {
res += dist(pixels[i], pixels[j]);
}
}
return res;
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
std::mt19937 Rand(std::random_device{}());
auto data = new pixel *[H];
for (int i = 0; i < H; ++i) {
data[i] = new pixel[W];
for (int j = 0; j < W; ++j) {
data[i][j] = pixel(R[i][j], G[i][j], B[i][j]);
}
}
auto clean = [&]() {
for (int i = 0; i < H; ++i) {
delete[] data[i];
}
delete[] data;
};
std::vector<pixel> primaries = {
{190, 10, 10},
{238, 208, 3},
{57, 96, 188},
{240, 240, 240},
{0, 0, 0},
{174, 180, 194}};
auto primary = [&](pixel x) {
for (auto p: primaries) {
if (dist(x, p) < 0.1) return true;
}
return false;
};
int numP = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
numP += primary(data[i][j]);
}
}
if (numP > 40000) {
clean();
return 1;
}
// return 0;
int numG = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
numG += (dist(data[i][j], {108, 141, 71}) < 0.25) || (data[i][j].h > 75 && data[i][j].h < 150 && (data[i][j].l < 0.8) && (data[i][j].l > 0.2));
}
}
const double BLUE_THRESHOLD = 0.25;
int highB = 0, lowB = 0;
for (int i = 0; i < H / 2; ++i) {
for (int j = 0; j < W; ++j) {
highB += (dist(data[i][j], {160, 180, 215}) < BLUE_THRESHOLD);
}
}
for (int i = H / 2; i < H; ++i) {
for (int j = 0; j < W; ++j) {
lowB += (dist(data[i][j], {160, 180, 215}) < BLUE_THRESHOLD);
}
}
std::map<int, int> diffs;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (data[i][j].l < 0.2 || data[i][j].l > 0.8) continue;
int num = std::floor(data[i][j].h / 10);
diffs[num]++;
}
}
int numlarge = 0;
for (auto [a, b]: diffs) {
//#ifdef LOCAL
// std::cout << "Colour " << a << ": " << b << std::endl;
//#endif
if (b > H * W / 4) numlarge++;
}
if (numG > 2000 && (highB > lowB * 1.5 || lowB < 50)) {
clean();
return 2;
}
int numW = 0;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
if (data[i][j].l > 0.7) numW++;
}
}
double Noise = 0.0;
int rad = 10;
for (int sample = 0; sample < 100; ++sample) {
int r = Rand() % H;
int c = Rand() % W;
while (r - rad < 0 || r + rad >= H) {
r = Rand() % H;
}
while (c - rad < 0 || c + rad >= W) {
c = Rand() % W;
}
std::vector<pixel> pixels;
for (int i = r - rad; i <= r + rad; ++i) {
for (int j = c - rad; j <= c + rad; ++j) {
pixels.push_back(data[i][j]);
}
}
Noise += noise(pixels);
}
if (Noise >= 1000000) {
clean();
return 3;
}
clean();
return 4;
}
#ifdef ONLINE_JUDGE
int _R[500][500];
int _G[500][500];
int _B[500][500];
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T;
std::cin >> T;
for (int _ = 0; _ < T; ++_) {
int H, W;
std::cin >> H >> W;
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
int a;
std::cin >> a;
_R[i][j] = (a >> 16) & 0xff;
_G[i][j] = (a >> 8) & 0xff;
_B[i][j] = a & 0xff;
}
}
std::cout << style(H, W, _R, _G, _B) << std::endl;
}
}
#endif
Compilation message
artclass.cpp: In function 'double noise(std::vector<pixel>)':
artclass.cpp:48:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pixel>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 0; i < pixels.size(); ++i) {
| ~~^~~~~~~~~~~~~~~
artclass.cpp:49:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pixel>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int j = i + 1; j < pixels.size(); ++j) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
11084 KB |
Output is correct |
2 |
Correct |
63 ms |
8664 KB |
Output is correct |
3 |
Correct |
55 ms |
12996 KB |
Output is correct |
4 |
Correct |
82 ms |
13916 KB |
Output is correct |
5 |
Incorrect |
81 ms |
12880 KB |
Output isn't correct |
6 |
Correct |
70 ms |
11344 KB |
Output is correct |
7 |
Incorrect |
67 ms |
15056 KB |
Output isn't correct |
8 |
Correct |
52 ms |
12372 KB |
Output is correct |
9 |
Correct |
55 ms |
15152 KB |
Output is correct |
10 |
Correct |
49 ms |
12496 KB |
Output is correct |
11 |
Incorrect |
53 ms |
10320 KB |
Output isn't correct |
12 |
Correct |
53 ms |
14676 KB |
Output is correct |
13 |
Incorrect |
80 ms |
12944 KB |
Output isn't correct |
14 |
Correct |
84 ms |
13140 KB |
Output is correct |
15 |
Correct |
49 ms |
11764 KB |
Output is correct |
16 |
Correct |
49 ms |
12032 KB |
Output is correct |
17 |
Correct |
52 ms |
12124 KB |
Output is correct |
18 |
Correct |
83 ms |
13396 KB |
Output is correct |
19 |
Correct |
50 ms |
12112 KB |
Output is correct |
20 |
Correct |
67 ms |
9012 KB |
Output is correct |
21 |
Correct |
50 ms |
14168 KB |
Output is correct |
22 |
Correct |
43 ms |
5980 KB |
Output is correct |
23 |
Incorrect |
63 ms |
9308 KB |
Output isn't correct |
24 |
Correct |
73 ms |
10808 KB |
Output is correct |
25 |
Incorrect |
60 ms |
14320 KB |
Output isn't correct |
26 |
Incorrect |
44 ms |
10904 KB |
Output isn't correct |
27 |
Correct |
58 ms |
7764 KB |
Output is correct |
28 |
Correct |
43 ms |
12540 KB |
Output is correct |
29 |
Correct |
82 ms |
12500 KB |
Output is correct |
30 |
Incorrect |
54 ms |
13400 KB |
Output isn't correct |
31 |
Correct |
52 ms |
14928 KB |
Output is correct |
32 |
Correct |
56 ms |
13304 KB |
Output is correct |
33 |
Correct |
65 ms |
8796 KB |
Output is correct |
34 |
Correct |
44 ms |
11348 KB |
Output is correct |
35 |
Incorrect |
47 ms |
10576 KB |
Output isn't correct |
36 |
Correct |
59 ms |
12924 KB |
Output is correct |
37 |
Incorrect |
56 ms |
13276 KB |
Output isn't correct |
38 |
Correct |
49 ms |
12312 KB |
Output is correct |
39 |
Correct |
77 ms |
12880 KB |
Output is correct |
40 |
Correct |
78 ms |
13116 KB |
Output is correct |
41 |
Correct |
64 ms |
10232 KB |
Output is correct |
42 |
Correct |
84 ms |
12880 KB |
Output is correct |
43 |
Correct |
56 ms |
7360 KB |
Output is correct |
44 |
Incorrect |
93 ms |
14672 KB |
Output isn't correct |
45 |
Correct |
80 ms |
11856 KB |
Output is correct |
46 |
Incorrect |
91 ms |
14936 KB |
Output isn't correct |
47 |
Correct |
52 ms |
12944 KB |
Output is correct |
48 |
Correct |
50 ms |
14420 KB |
Output is correct |
49 |
Incorrect |
44 ms |
10072 KB |
Output isn't correct |
50 |
Incorrect |
45 ms |
12880 KB |
Output isn't correct |
51 |
Correct |
56 ms |
7528 KB |
Output is correct |
52 |
Incorrect |
89 ms |
14216 KB |
Output isn't correct |
53 |
Correct |
82 ms |
12372 KB |
Output is correct |
54 |
Correct |
57 ms |
12824 KB |
Output is correct |
55 |
Incorrect |
39 ms |
10332 KB |
Output isn't correct |
56 |
Incorrect |
96 ms |
14928 KB |
Output isn't correct |
57 |
Correct |
63 ms |
14704 KB |
Output is correct |
58 |
Correct |
79 ms |
11600 KB |
Output is correct |
59 |
Correct |
70 ms |
10372 KB |
Output is correct |
60 |
Correct |
52 ms |
14620 KB |
Output is correct |
61 |
Correct |
82 ms |
12608 KB |
Output is correct |
62 |
Correct |
34 ms |
8684 KB |
Output is correct |
63 |
Correct |
53 ms |
12884 KB |
Output is correct |
64 |
Incorrect |
44 ms |
12628 KB |
Output isn't correct |
65 |
Correct |
84 ms |
13396 KB |
Output is correct |
66 |
Correct |
54 ms |
14932 KB |
Output is correct |
67 |
Correct |
55 ms |
12880 KB |
Output is correct |
68 |
Correct |
46 ms |
12880 KB |
Output is correct |
69 |
Correct |
74 ms |
11348 KB |
Output is correct |
70 |
Correct |
70 ms |
10068 KB |
Output is correct |
71 |
Correct |
81 ms |
12316 KB |
Output is correct |
72 |
Correct |
52 ms |
12268 KB |
Output is correct |
73 |
Incorrect |
62 ms |
12800 KB |
Output isn't correct |
74 |
Correct |
37 ms |
9688 KB |
Output is correct |
75 |
Correct |
42 ms |
10564 KB |
Output is correct |
76 |
Correct |
33 ms |
10576 KB |
Output is correct |
77 |
Correct |
77 ms |
11756 KB |
Output is correct |
78 |
Correct |
57 ms |
12888 KB |
Output is correct |
79 |
Incorrect |
43 ms |
11164 KB |
Output isn't correct |
80 |
Correct |
57 ms |
14932 KB |
Output is correct |
81 |
Correct |
80 ms |
12884 KB |
Output is correct |
82 |
Correct |
54 ms |
12864 KB |
Output is correct |
83 |
Correct |
52 ms |
11860 KB |
Output is correct |
84 |
Incorrect |
94 ms |
15128 KB |
Output isn't correct |
85 |
Correct |
81 ms |
12372 KB |
Output is correct |
86 |
Correct |
71 ms |
11352 KB |
Output is correct |
87 |
Incorrect |
60 ms |
13180 KB |
Output isn't correct |
88 |
Correct |
75 ms |
12772 KB |
Output is correct |
89 |
Correct |
55 ms |
12628 KB |
Output is correct |
90 |
Correct |
46 ms |
13396 KB |
Output is correct |
91 |
Correct |
53 ms |
14720 KB |
Output is correct |
92 |
Incorrect |
47 ms |
13816 KB |
Output isn't correct |
93 |
Incorrect |
54 ms |
12128 KB |
Output isn't correct |
94 |
Correct |
56 ms |
13140 KB |
Output is correct |
95 |
Incorrect |
30 ms |
9048 KB |
Output isn't correct |
96 |
Correct |
42 ms |
4956 KB |
Output is correct |
97 |
Correct |
53 ms |
12884 KB |
Output is correct |
98 |
Correct |
77 ms |
13020 KB |
Output is correct |
99 |
Correct |
71 ms |
10320 KB |
Output is correct |
100 |
Correct |
78 ms |
11600 KB |
Output is correct |
101 |
Correct |
55 ms |
13068 KB |
Output is correct |
102 |
Incorrect |
52 ms |
13048 KB |
Output isn't correct |