#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#include "artclass.h"
vector<int> dx = {0, 0, 1, -1};
vector<int> dy = {-1, 1, 0, 0};
vector<vector<int>> was, r, g, b;
int n, m;
bool good(int x, int y)
{
return x >= 0 and y >= 0 and x < n and y < m;
}
int O = 0;
struct DSU
{
vector<int> sz, p;
void init(int n)
{
p.resize(n);
sz.resize(n);
for (int i = 0; i < n; ++i)
p[i] = i;
}
int getRoot(int v)
{
return p[v] == v ? v : p[v] = getRoot(p[v]);
}
void merge(int a, int b)
{
a = getRoot(a);
b = getRoot(b);
if (a == b)
return;
sz[a] += sz[b];
p[b] = a;
}
};
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500])
{
r.resize(H + 100, vector<int>(W + 100));
g.resize(H + 100, vector<int>(W + 100));
b.resize(H + 100, vector<int>(W + 100));
n = H;
m = W;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
{
r[i][j] = R[i][j];
g[i][j] = G[i][j];
b[i][j] = B[i][j];
}
vector<int> d;
{
DSU dsu;
dsu.init(n * m);
for (int x = 0; x < n; ++x)
for (int y = 0; y < m; ++y)
for (int d = 0; d < 4; ++d)
{
int tox = x + dx[d];
int toy = y + dy[d];
if (good(tox, toy))
{
int diff = abs(r[x][y] - r[tox][toy]) + abs(g[x][y] - g[tox][toy]) + abs(b[x][y] - b[tox][toy]);
if (diff <= 40)
dsu.merge(x * m + y, tox * m + toy);
}
}
for (int i = 0; i < n * m; ++i)
if (dsu.p[i] == i)
d.pb(i);
}
sort(all(d));
reverse(all(d));
if ((int)d.size() == 1)
return 4;
if (d[0] + d[1] >= (double)(n * m) * 0.70)
return 4;
d.clear();
{
DSU dsu;
dsu.init(n * m);
for (int x = 0; x < n; ++x)
for (int y = 0; y < m; ++y)
for (int d = 0; d < 4; ++d)
{
int tox = x + dx[d];
int toy = y + dy[d];
if (good(tox, toy))
{
int diff = abs(r[x][y] - r[tox][toy]) + abs(g[x][y] - g[tox][toy]) + abs(b[x][y] - b[tox][toy]);
if (diff <= 5)
dsu.merge(x * m + y, tox * m + toy);
}
}
for (int i = 0; i < n * m; ++i)
if (dsu.p[i] == i)
d.pb(i);
}
if (((double)d.size() / (double)(H * W)) <= 0.1)
return 1;
if (((double)d.size() / (double)(H * W)) >= 0.7)
return 3;
return 2;
}
// #include <stdio.h>
// #include "artclass.h"
// #include <assert.h>
// static int DIM[2];
// static int R[500][500];
// static int G[500][500];
// static int B[500][500];
// int main()
// {
// assert(scanf("%d", &DIM[1]) == 1);
// assert(scanf("%d", &DIM[0]) == 1);
// for (int i = 0; i < DIM[0]; i++)
// for (int j = 0; j < DIM[1]; j++)
// assert(scanf("%d %d %d", &R[i][j], &G[i][j], &B[i][j]) == 3);
// printf("%d\n", style(DIM[0], DIM[1], R, G, B));
// return 0;
// }
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
36 ms |
8528 KB |
Output isn't correct |
2 |
Incorrect |
54 ms |
10952 KB |
Output isn't correct |
3 |
Incorrect |
12 ms |
5160 KB |
Output isn't correct |
4 |
Incorrect |
52 ms |
10332 KB |
Output isn't correct |
5 |
Incorrect |
44 ms |
9596 KB |
Output isn't correct |
6 |
Incorrect |
36 ms |
9168 KB |
Output isn't correct |
7 |
Incorrect |
42 ms |
9440 KB |
Output isn't correct |
8 |
Incorrect |
38 ms |
8788 KB |
Output isn't correct |
9 |
Incorrect |
39 ms |
9684 KB |
Output isn't correct |
10 |
Incorrect |
43 ms |
9696 KB |
Output isn't correct |
11 |
Incorrect |
51 ms |
10836 KB |
Output isn't correct |
12 |
Correct |
43 ms |
9812 KB |
Output is correct |
13 |
Incorrect |
44 ms |
9808 KB |
Output isn't correct |
14 |
Incorrect |
38 ms |
8540 KB |
Output isn't correct |
15 |
Incorrect |
52 ms |
11092 KB |
Output isn't correct |
16 |
Correct |
41 ms |
9816 KB |
Output is correct |
17 |
Incorrect |
43 ms |
9760 KB |
Output isn't correct |
18 |
Incorrect |
39 ms |
9088 KB |
Output isn't correct |
19 |
Correct |
36 ms |
8604 KB |
Output is correct |
20 |
Incorrect |
43 ms |
9808 KB |
Output isn't correct |
21 |
Correct |
13 ms |
5724 KB |
Output is correct |
22 |
Incorrect |
43 ms |
9660 KB |
Output isn't correct |
23 |
Correct |
44 ms |
10196 KB |
Output is correct |
24 |
Incorrect |
41 ms |
9792 KB |
Output isn't correct |
25 |
Incorrect |
56 ms |
10128 KB |
Output isn't correct |
26 |
Incorrect |
50 ms |
10660 KB |
Output isn't correct |
27 |
Incorrect |
28 ms |
7504 KB |
Output isn't correct |
28 |
Incorrect |
35 ms |
8532 KB |
Output isn't correct |
29 |
Incorrect |
45 ms |
9828 KB |
Output isn't correct |
30 |
Incorrect |
42 ms |
9024 KB |
Output isn't correct |
31 |
Incorrect |
57 ms |
11088 KB |
Output isn't correct |
32 |
Correct |
45 ms |
10324 KB |
Output is correct |
33 |
Incorrect |
46 ms |
10324 KB |
Output isn't correct |
34 |
Incorrect |
42 ms |
9296 KB |
Output isn't correct |
35 |
Incorrect |
49 ms |
10064 KB |
Output isn't correct |
36 |
Correct |
38 ms |
9076 KB |
Output is correct |
37 |
Correct |
51 ms |
11380 KB |
Output is correct |
38 |
Incorrect |
32 ms |
8532 KB |
Output isn't correct |
39 |
Incorrect |
45 ms |
9812 KB |
Output isn't correct |
40 |
Correct |
35 ms |
8788 KB |
Output is correct |
41 |
Incorrect |
51 ms |
10480 KB |
Output isn't correct |
42 |
Incorrect |
29 ms |
7884 KB |
Output isn't correct |
43 |
Incorrect |
46 ms |
10036 KB |
Output isn't correct |
44 |
Incorrect |
48 ms |
10192 KB |
Output isn't correct |
45 |
Incorrect |
40 ms |
8956 KB |
Output isn't correct |
46 |
Correct |
41 ms |
9852 KB |
Output is correct |
47 |
Incorrect |
34 ms |
8272 KB |
Output isn't correct |
48 |
Correct |
40 ms |
9300 KB |
Output is correct |
49 |
Correct |
47 ms |
10580 KB |
Output is correct |
50 |
Incorrect |
43 ms |
9804 KB |
Output isn't correct |
51 |
Correct |
41 ms |
9812 KB |
Output is correct |
52 |
Incorrect |
52 ms |
10960 KB |
Output isn't correct |
53 |
Correct |
45 ms |
10400 KB |
Output is correct |
54 |
Correct |
42 ms |
9808 KB |
Output is correct |
55 |
Incorrect |
54 ms |
10836 KB |
Output isn't correct |
56 |
Incorrect |
42 ms |
9448 KB |
Output isn't correct |
57 |
Incorrect |
23 ms |
6736 KB |
Output isn't correct |
58 |
Incorrect |
51 ms |
11104 KB |
Output isn't correct |
59 |
Incorrect |
43 ms |
9812 KB |
Output isn't correct |
60 |
Incorrect |
41 ms |
9000 KB |
Output isn't correct |
61 |
Incorrect |
33 ms |
8788 KB |
Output isn't correct |
62 |
Incorrect |
47 ms |
9984 KB |
Output isn't correct |
63 |
Incorrect |
51 ms |
10052 KB |
Output isn't correct |
64 |
Incorrect |
43 ms |
9368 KB |
Output isn't correct |
65 |
Incorrect |
28 ms |
7508 KB |
Output isn't correct |
66 |
Incorrect |
41 ms |
9592 KB |
Output isn't correct |
67 |
Incorrect |
44 ms |
9300 KB |
Output isn't correct |
68 |
Incorrect |
48 ms |
10580 KB |
Output isn't correct |
69 |
Incorrect |
50 ms |
10836 KB |
Output isn't correct |
70 |
Incorrect |
29 ms |
7508 KB |
Output isn't correct |
71 |
Incorrect |
42 ms |
9532 KB |
Output isn't correct |
72 |
Correct |
32 ms |
8544 KB |
Output is correct |
73 |
Correct |
25 ms |
7604 KB |
Output is correct |
74 |
Incorrect |
44 ms |
10100 KB |
Output isn't correct |
75 |
Correct |
31 ms |
8284 KB |
Output is correct |
76 |
Incorrect |
44 ms |
10288 KB |
Output isn't correct |
77 |
Incorrect |
28 ms |
7880 KB |
Output isn't correct |
78 |
Incorrect |
28 ms |
7704 KB |
Output isn't correct |
79 |
Incorrect |
49 ms |
10572 KB |
Output isn't correct |
80 |
Correct |
44 ms |
10068 KB |
Output is correct |
81 |
Incorrect |
57 ms |
10444 KB |
Output isn't correct |
82 |
Correct |
46 ms |
10320 KB |
Output is correct |
83 |
Correct |
39 ms |
9592 KB |
Output is correct |
84 |
Incorrect |
52 ms |
11088 KB |
Output isn't correct |
85 |
Incorrect |
52 ms |
9832 KB |
Output isn't correct |
86 |
Incorrect |
45 ms |
9960 KB |
Output isn't correct |
87 |
Incorrect |
47 ms |
10192 KB |
Output isn't correct |
88 |
Incorrect |
43 ms |
9556 KB |
Output isn't correct |
89 |
Incorrect |
41 ms |
9556 KB |
Output isn't correct |
90 |
Incorrect |
52 ms |
11092 KB |
Output isn't correct |
91 |
Incorrect |
46 ms |
9960 KB |
Output isn't correct |
92 |
Incorrect |
46 ms |
10064 KB |
Output isn't correct |
93 |
Incorrect |
54 ms |
11344 KB |
Output isn't correct |
94 |
Correct |
35 ms |
9144 KB |
Output is correct |
95 |
Incorrect |
45 ms |
9936 KB |
Output isn't correct |
96 |
Incorrect |
25 ms |
6992 KB |
Output isn't correct |
97 |
Correct |
44 ms |
9676 KB |
Output is correct |
98 |
Correct |
29 ms |
8388 KB |
Output is correct |
99 |
Incorrect |
34 ms |
8436 KB |
Output isn't correct |
100 |
Correct |
45 ms |
10252 KB |
Output is correct |
101 |
Incorrect |
50 ms |
11088 KB |
Output isn't correct |
102 |
Incorrect |
25 ms |
6784 KB |
Output isn't correct |