#include "artclass.h"
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <cassert>
#include <vector>
#include <set>
typedef long long llong;
const int MAXN = 500;
const int INF = 1e9;
int H, W;
struct Cell
{
int x, y, z;
friend int operator - (const Cell &a, const Cell &b)
{
return abs(a.x - b.x) + abs(a.y - b.y) + abs(a.z - b.z);
}
friend bool operator < (const Cell &a, const Cell &b)
{
return (a.x < b.x || (a.x == b.x && a.y < b.y) || (a.x == b.x && a.y == b.y && a.z < b.z));
}
};
const int CNTBASE = 7;
int compBase[CNTBASE] = {2, 5, 10, 15, 20, 50, 100};
bool close(Cell a, Cell b, int idx)
{
return abs(a.x - b.x) < compBase[idx] && abs(a.y - b.y) < compBase[idx] && abs(a.z - b.z) < compBase[idx];
}
const int BASE = 5;
const int BASE2 = 10;
int convert(int x)
{
if (x % BASE < BASE / 2) return x - (x % BASE);
return x + BASE - (x % BASE);
}
std::set <Cell> s;
Cell pixel[MAXN][MAXN];
Cell block[MAXN][MAXN];
std::pair <int,int> delta[] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
bool out(int x, int y)
{
return (x == -1 || y == -1 || x == H / BASE2 || y == W / BASE2);
}
bool outDFS(int x, int y)
{
return (x == -1 || y == -1 || x == H || y == W);
}
bool vis[MAXN][MAXN][CNTBASE];
void dfs(int x, int y, int cnt)
{
vis[x][y][cnt] = true;
for (const auto &[dx, dy] : delta)
{
if (outDFS(x + dx, y + dy) || !close(pixel[x][y], pixel[x + dx][y + dy], cnt) || vis[x + dx][y + dy][cnt])
{
continue;
}
dfs(x + dx, y + dy, cnt);
}
}
int style(int h, int w, int R[500][500], int G[500][500], int B[500][500])
{
H = h;
W = w;
llong sum = 0;
llong green = 0;
for (int i = 0 ; i < H ; ++i)
{
for (int j = 0 ; j < W ; ++j)
{
sum += R[i][j];
sum += G[i][j];
sum += B[i][j];
pixel[i][j] = {R[i][j], G[i][j], B[i][j]};
block[i / BASE2][j / BASE2].x += R[i][j];
block[i / BASE2][j / BASE2].y += G[i][j];
block[i / BASE2][j / BASE2].z += B[i][j];
green += (G[i][j] - std::min(R[i][j], B[i][j]));
s.insert({convert(R[i][j]), convert(G[i][j]), convert(B[i][j])});
}
}
llong diff = 0;
llong diff2 = 0;
for (int i = 0 ; i * BASE2 < H ; ++i)
{
for (int j = 0 ; j * BASE2 < W ; ++j)
{
for (const auto &[dx, dy] : delta)
{
if (out(i + dx, j + dy))
{
continue;
}
diff += block[i][j] - block[i + dx][j + dy];
}
}
}
for (int i = 0 ; i < H ; ++i)
{
for (int j = 0 ; j < W ; ++j)
{
for (const auto &[dx, dy] : delta)
{
if (out(i + dx, j + dy))
{
continue;
}
diff2 += pixel[i][j] - pixel[i + dx][j + dy];
}
}
}
int compCnt[CNTBASE];
for (int k = 0 ; k < CNTBASE ; ++k)
{
compCnt[k] = 0;
for (int i = 0 ; i < H ; ++i)
{
for (int j = 0 ; j < W ; ++j)
{
if (!vis[i][j][k])
{
compCnt[k]++;
dfs(i, j, k);
}
}
}
}
if (compCnt[6] > 20 || compCnt[5] > 4000) return 3;
if (compCnt[6] <= 5 && compCnt[4] < 50) return 4;
if (compCnt[1] < 60000 && (compCnt[1] > 9000 || compCnt[4] > 150)) return 1;
if ((compCnt[1] < 9000 || compCnt[4] < 150)) return 4;
if (compCnt[4] < 15000) return 2;
if (s.size() > 16000)
{
if (compCnt[5] > 50) return 1;
return 2;
}
return 3;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
135 ms |
20560 KB |
Output is correct |
2 |
Incorrect |
109 ms |
26940 KB |
Output isn't correct |
3 |
Incorrect |
95 ms |
24288 KB |
Output isn't correct |
4 |
Incorrect |
122 ms |
29116 KB |
Output isn't correct |
5 |
Correct |
122 ms |
26304 KB |
Output is correct |
6 |
Correct |
64 ms |
15400 KB |
Output is correct |
7 |
Correct |
86 ms |
21048 KB |
Output is correct |
8 |
Correct |
69 ms |
15368 KB |
Output is correct |
9 |
Correct |
121 ms |
25636 KB |
Output is correct |
10 |
Correct |
106 ms |
20808 KB |
Output is correct |
11 |
Correct |
119 ms |
26272 KB |
Output is correct |
12 |
Correct |
109 ms |
24072 KB |
Output is correct |
13 |
Incorrect |
71 ms |
18016 KB |
Output isn't correct |
14 |
Incorrect |
106 ms |
24336 KB |
Output isn't correct |
15 |
Correct |
59 ms |
12956 KB |
Output is correct |
16 |
Incorrect |
123 ms |
23060 KB |
Output isn't correct |
17 |
Correct |
106 ms |
26448 KB |
Output is correct |
18 |
Correct |
101 ms |
24704 KB |
Output is correct |
19 |
Correct |
135 ms |
31380 KB |
Output is correct |
20 |
Correct |
112 ms |
24180 KB |
Output is correct |
21 |
Incorrect |
112 ms |
19672 KB |
Output isn't correct |
22 |
Correct |
114 ms |
22808 KB |
Output is correct |
23 |
Correct |
122 ms |
29564 KB |
Output is correct |
24 |
Correct |
52 ms |
11012 KB |
Output is correct |
25 |
Correct |
70 ms |
16388 KB |
Output is correct |
26 |
Correct |
117 ms |
28364 KB |
Output is correct |
27 |
Correct |
110 ms |
24700 KB |
Output is correct |
28 |
Correct |
119 ms |
26464 KB |
Output is correct |
29 |
Correct |
96 ms |
23712 KB |
Output is correct |
30 |
Correct |
120 ms |
26316 KB |
Output is correct |
31 |
Correct |
108 ms |
23216 KB |
Output is correct |
32 |
Correct |
116 ms |
25536 KB |
Output is correct |
33 |
Correct |
88 ms |
20688 KB |
Output is correct |
34 |
Incorrect |
125 ms |
28604 KB |
Output isn't correct |
35 |
Incorrect |
119 ms |
27184 KB |
Output isn't correct |
36 |
Correct |
58 ms |
11368 KB |
Output is correct |
37 |
Correct |
124 ms |
27508 KB |
Output is correct |
38 |
Correct |
134 ms |
29920 KB |
Output is correct |
39 |
Correct |
109 ms |
28740 KB |
Output is correct |
40 |
Correct |
77 ms |
21928 KB |
Output is correct |
41 |
Incorrect |
113 ms |
24848 KB |
Output isn't correct |
42 |
Correct |
63 ms |
19660 KB |
Output is correct |
43 |
Correct |
123 ms |
27464 KB |
Output is correct |
44 |
Correct |
88 ms |
18740 KB |
Output is correct |
45 |
Correct |
120 ms |
21752 KB |
Output is correct |
46 |
Correct |
99 ms |
21368 KB |
Output is correct |
47 |
Incorrect |
118 ms |
27484 KB |
Output isn't correct |
48 |
Incorrect |
133 ms |
23716 KB |
Output isn't correct |
49 |
Correct |
83 ms |
20316 KB |
Output is correct |
50 |
Correct |
66 ms |
13992 KB |
Output is correct |
51 |
Correct |
94 ms |
21068 KB |
Output is correct |
52 |
Correct |
82 ms |
21344 KB |
Output is correct |
53 |
Correct |
120 ms |
26548 KB |
Output is correct |
54 |
Incorrect |
106 ms |
23084 KB |
Output isn't correct |
55 |
Correct |
85 ms |
15488 KB |
Output is correct |
56 |
Incorrect |
116 ms |
24960 KB |
Output isn't correct |
57 |
Correct |
117 ms |
27212 KB |
Output is correct |
58 |
Correct |
80 ms |
19044 KB |
Output is correct |
59 |
Incorrect |
116 ms |
28088 KB |
Output isn't correct |
60 |
Correct |
99 ms |
22348 KB |
Output is correct |
61 |
Correct |
129 ms |
23808 KB |
Output is correct |
62 |
Incorrect |
27 ms |
6204 KB |
Output isn't correct |
63 |
Correct |
128 ms |
27256 KB |
Output is correct |
64 |
Correct |
118 ms |
21324 KB |
Output is correct |
65 |
Correct |
92 ms |
17116 KB |
Output is correct |
66 |
Correct |
114 ms |
25456 KB |
Output is correct |
67 |
Correct |
112 ms |
22580 KB |
Output is correct |
68 |
Correct |
112 ms |
24744 KB |
Output is correct |
69 |
Correct |
124 ms |
26680 KB |
Output is correct |
70 |
Correct |
130 ms |
26572 KB |
Output is correct |
71 |
Correct |
96 ms |
24508 KB |
Output is correct |
72 |
Incorrect |
127 ms |
22864 KB |
Output isn't correct |
73 |
Correct |
103 ms |
27840 KB |
Output is correct |
74 |
Correct |
89 ms |
23920 KB |
Output is correct |
75 |
Incorrect |
117 ms |
27468 KB |
Output isn't correct |
76 |
Incorrect |
125 ms |
27088 KB |
Output isn't correct |
77 |
Incorrect |
85 ms |
23172 KB |
Output isn't correct |
78 |
Correct |
124 ms |
24120 KB |
Output is correct |
79 |
Correct |
87 ms |
22460 KB |
Output is correct |
80 |
Incorrect |
132 ms |
28184 KB |
Output isn't correct |
81 |
Correct |
73 ms |
15024 KB |
Output is correct |
82 |
Correct |
72 ms |
19636 KB |
Output is correct |
83 |
Correct |
110 ms |
25428 KB |
Output is correct |
84 |
Correct |
131 ms |
26900 KB |
Output is correct |
85 |
Correct |
76 ms |
19332 KB |
Output is correct |
86 |
Correct |
109 ms |
24084 KB |
Output is correct |
87 |
Incorrect |
105 ms |
23936 KB |
Output isn't correct |
88 |
Correct |
114 ms |
27024 KB |
Output is correct |
89 |
Correct |
112 ms |
25260 KB |
Output is correct |
90 |
Incorrect |
115 ms |
26096 KB |
Output isn't correct |
91 |
Incorrect |
134 ms |
29668 KB |
Output isn't correct |
92 |
Correct |
111 ms |
24508 KB |
Output is correct |
93 |
Correct |
29 ms |
13396 KB |
Output is correct |
94 |
Correct |
98 ms |
23168 KB |
Output is correct |
95 |
Correct |
108 ms |
20440 KB |
Output is correct |
96 |
Correct |
123 ms |
25660 KB |
Output is correct |
97 |
Correct |
90 ms |
19108 KB |
Output is correct |
98 |
Incorrect |
123 ms |
28116 KB |
Output isn't correct |
99 |
Correct |
119 ms |
26588 KB |
Output is correct |
100 |
Correct |
122 ms |
27608 KB |
Output is correct |
101 |
Incorrect |
127 ms |
23832 KB |
Output isn't correct |
102 |
Incorrect |
113 ms |
27148 KB |
Output isn't correct |