# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
940647 | Der_Vlapos | Art Class (IOI13_artclass) | C++17 | 57 ms | 11380 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
// }
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |