#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;
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 BASE3 = 5;
bool close(Cell a, Cell b)
{
return abs(a.x - b.x) < BASE3 && abs(a.y - b.y) < BASE3 && abs(a.z - b.z) < BASE3;
}
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 == MAXN / BASE2 || y == MAXN / BASE2);
}
bool outDFS(int x, int y)
{
return (x == -1 || y == -1 || x == MAXN || y == MAXN);
}
bool vis[MAXN][MAXN];
void dfs(int x, int y)
{
vis[x][y] = true;
for (const auto &[dx, dy] : delta)
{
if (outDFS(x + dx, y + dy) || !close(pixel[x][y], pixel[x + dx][y + dy]) || vis[x + dx][y + dy])
{
continue;
}
dfs(x + dx, y + dy);
}
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500])
{
llong sum = 0;
llong green = 0;
for (int i = 0 ; i < MAXN ; ++i)
{
for (int j = 0 ; j < MAXN ; ++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] > 128);
green -= (B[i][j] > 64 || G[i][j] > 64);
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 < MAXN ; ++i)
{
for (int j = 0 ; j * BASE2 < MAXN ; ++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 < MAXN ; ++i)
{
for (int j = 0 ; j < MAXN ; ++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 = 0;
for (int i = 0 ; i < MAXN ; ++i)
{
for (int j = 0 ; j < MAXN ; ++j)
{
if (!vis[i][j])
{
compCnt++;
dfs(i, j);
}
}
}
srand(time(nullptr));
double ratio = (double)green / (MAXN * MAXN);
double ratio2 = (double)s.size() / (MAXN * MAXN);
// std::cout << "ratio: " << std::fixed << ratio << ' ' << ratio2 << ' ' << diff << ' ' << diff2 << ' ' << compCnt << '\n';
if (compCnt < 9000) return 4;
if (compCnt < 60000) return 1;
// if (ratio > 0.3) return 2;
// return 3;
return 2 + rand()%2;
}
Compilation message
artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:141:12: warning: unused variable 'ratio' [-Wunused-variable]
141 | double ratio = (double)green / (MAXN * MAXN);
| ^~~~~
artclass.cpp:142:12: warning: unused variable 'ratio2' [-Wunused-variable]
142 | double ratio2 = (double)s.size() / (MAXN * MAXN);
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
10776 KB |
Output is correct |
2 |
Correct |
65 ms |
11192 KB |
Output is correct |
3 |
Correct |
59 ms |
11980 KB |
Output is correct |
4 |
Correct |
60 ms |
11148 KB |
Output is correct |
5 |
Correct |
45 ms |
14528 KB |
Output is correct |
6 |
Incorrect |
57 ms |
12148 KB |
Output isn't correct |
7 |
Incorrect |
55 ms |
14064 KB |
Output isn't correct |
8 |
Incorrect |
53 ms |
11744 KB |
Output isn't correct |
9 |
Correct |
61 ms |
11108 KB |
Output is correct |
10 |
Incorrect |
70 ms |
11788 KB |
Output isn't correct |
11 |
Correct |
54 ms |
10580 KB |
Output is correct |
12 |
Incorrect |
62 ms |
11716 KB |
Output isn't correct |
13 |
Correct |
49 ms |
15072 KB |
Output is correct |
14 |
Incorrect |
59 ms |
12324 KB |
Output isn't correct |
15 |
Correct |
51 ms |
13820 KB |
Output is correct |
16 |
Correct |
51 ms |
19264 KB |
Output is correct |
17 |
Incorrect |
44 ms |
14284 KB |
Output isn't correct |
18 |
Incorrect |
66 ms |
11276 KB |
Output isn't correct |
19 |
Correct |
63 ms |
12644 KB |
Output is correct |
20 |
Incorrect |
45 ms |
14512 KB |
Output isn't correct |
21 |
Incorrect |
52 ms |
14984 KB |
Output isn't correct |
22 |
Incorrect |
65 ms |
11964 KB |
Output isn't correct |
23 |
Correct |
64 ms |
13656 KB |
Output is correct |
24 |
Incorrect |
46 ms |
13740 KB |
Output isn't correct |
25 |
Correct |
65 ms |
12080 KB |
Output is correct |
26 |
Correct |
67 ms |
12188 KB |
Output is correct |
27 |
Correct |
38 ms |
16036 KB |
Output is correct |
28 |
Correct |
50 ms |
13656 KB |
Output is correct |
29 |
Correct |
64 ms |
13600 KB |
Output is correct |
30 |
Correct |
40 ms |
15672 KB |
Output is correct |
31 |
Correct |
57 ms |
12188 KB |
Output is correct |
32 |
Correct |
60 ms |
10140 KB |
Output is correct |
33 |
Correct |
51 ms |
13436 KB |
Output is correct |
34 |
Incorrect |
59 ms |
12480 KB |
Output isn't correct |
35 |
Correct |
43 ms |
14096 KB |
Output is correct |
36 |
Incorrect |
70 ms |
10396 KB |
Output isn't correct |
37 |
Incorrect |
52 ms |
15348 KB |
Output isn't correct |
38 |
Correct |
30 ms |
19176 KB |
Output is correct |
39 |
Incorrect |
58 ms |
13556 KB |
Output isn't correct |
40 |
Correct |
58 ms |
11704 KB |
Output is correct |
41 |
Incorrect |
54 ms |
12664 KB |
Output isn't correct |
42 |
Correct |
61 ms |
11588 KB |
Output is correct |
43 |
Incorrect |
73 ms |
11644 KB |
Output isn't correct |
44 |
Correct |
60 ms |
12400 KB |
Output is correct |
45 |
Incorrect |
80 ms |
9612 KB |
Output isn't correct |
46 |
Correct |
63 ms |
11360 KB |
Output is correct |
47 |
Incorrect |
58 ms |
14284 KB |
Output isn't correct |
48 |
Correct |
61 ms |
12520 KB |
Output is correct |
49 |
Correct |
58 ms |
11816 KB |
Output is correct |
50 |
Correct |
60 ms |
11912 KB |
Output is correct |
51 |
Correct |
53 ms |
15692 KB |
Output is correct |
52 |
Correct |
61 ms |
13348 KB |
Output is correct |
53 |
Incorrect |
74 ms |
12020 KB |
Output isn't correct |
54 |
Correct |
55 ms |
19276 KB |
Output is correct |
55 |
Incorrect |
46 ms |
14332 KB |
Output isn't correct |
56 |
Incorrect |
55 ms |
11876 KB |
Output isn't correct |
57 |
Correct |
49 ms |
14332 KB |
Output is correct |
58 |
Correct |
58 ms |
18252 KB |
Output is correct |
59 |
Incorrect |
54 ms |
13776 KB |
Output isn't correct |
60 |
Correct |
44 ms |
14752 KB |
Output is correct |
61 |
Incorrect |
58 ms |
16544 KB |
Output isn't correct |
62 |
Incorrect |
48 ms |
14548 KB |
Output isn't correct |
63 |
Incorrect |
52 ms |
16352 KB |
Output isn't correct |
64 |
Correct |
62 ms |
12236 KB |
Output is correct |
65 |
Correct |
62 ms |
12096 KB |
Output is correct |
66 |
Incorrect |
64 ms |
11396 KB |
Output isn't correct |
67 |
Incorrect |
65 ms |
11788 KB |
Output isn't correct |
68 |
Correct |
86 ms |
12180 KB |
Output is correct |
69 |
Incorrect |
52 ms |
13152 KB |
Output isn't correct |
70 |
Correct |
54 ms |
13284 KB |
Output is correct |
71 |
Incorrect |
65 ms |
11488 KB |
Output isn't correct |
72 |
Incorrect |
69 ms |
9820 KB |
Output isn't correct |
73 |
Correct |
45 ms |
13836 KB |
Output is correct |
74 |
Correct |
63 ms |
12920 KB |
Output is correct |
75 |
Incorrect |
57 ms |
11652 KB |
Output isn't correct |
76 |
Incorrect |
62 ms |
11736 KB |
Output isn't correct |
77 |
Correct |
66 ms |
13132 KB |
Output is correct |
78 |
Correct |
44 ms |
15436 KB |
Output is correct |
79 |
Incorrect |
61 ms |
11144 KB |
Output isn't correct |
80 |
Correct |
45 ms |
13804 KB |
Output is correct |
81 |
Incorrect |
66 ms |
12640 KB |
Output isn't correct |
82 |
Incorrect |
64 ms |
11648 KB |
Output isn't correct |
83 |
Incorrect |
36 ms |
17580 KB |
Output isn't correct |
84 |
Correct |
48 ms |
12164 KB |
Output is correct |
85 |
Incorrect |
57 ms |
12136 KB |
Output isn't correct |
86 |
Incorrect |
66 ms |
12048 KB |
Output isn't correct |
87 |
Incorrect |
52 ms |
14876 KB |
Output isn't correct |
88 |
Incorrect |
44 ms |
15664 KB |
Output isn't correct |
89 |
Correct |
62 ms |
12788 KB |
Output is correct |
90 |
Correct |
68 ms |
12044 KB |
Output is correct |
91 |
Incorrect |
50 ms |
13760 KB |
Output isn't correct |
92 |
Incorrect |
44 ms |
14440 KB |
Output isn't correct |
93 |
Correct |
62 ms |
11912 KB |
Output is correct |
94 |
Correct |
53 ms |
11980 KB |
Output is correct |
95 |
Incorrect |
72 ms |
10700 KB |
Output isn't correct |
96 |
Correct |
56 ms |
14064 KB |
Output is correct |
97 |
Correct |
74 ms |
12476 KB |
Output is correct |
98 |
Incorrect |
64 ms |
12936 KB |
Output isn't correct |
99 |
Correct |
66 ms |
12348 KB |
Output is correct |
100 |
Incorrect |
67 ms |
12492 KB |
Output isn't correct |
101 |
Incorrect |
68 ms |
11144 KB |
Output isn't correct |
102 |
Incorrect |
61 ms |
14328 KB |
Output isn't correct |