# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
518529 | tabr | Art Class (IOI13_artclass) | C++17 | 65 ms | 5164 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;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
#ifndef tabr
#include "artclass.h"
#endif
struct dsu {
vector<int> p;
vector<int> sz;
int n;
dsu(int _n) : n(_n) {
p.resize(n);
iota(p.begin(), p.end(), 0);
sz.assign(n, 1);
}
inline int get(int x) {
if (p[x] == x) {
return x;
} else {
return p[x] = get(p[x]);
}
}
inline bool unite(int x, int y) {
x = get(x);
y = get(y);
if (x == y) {
return false;
}
if (sz[x] > sz[y]) {
swap(x, y);
}
p[x] = y;
sz[y] += sz[x];
return true;
}
inline bool same(int x, int y) {
return (get(x) == get(y));
}
};
int style(int h, int w, int r[500][500], int g[500][500], int b[500][500]) {
dsu uf(h * w);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w - 1; j++) {
int dr = abs(r[i][j] - r[i][j + 1]);
int dg = abs(g[i][j] - g[i][j + 1]);
int db = abs(b[i][j] - b[i][j + 1]);
if (min({dr, dg, db}) < 30) {
uf.unite(i * w + j, i * w + j + 1);
}
}
}
for (int i = 0; i < h - 1; i++) {
for (int j = 0; j < w; j++) {
int dr = abs(r[i][j] - r[i + 1][j]);
int dg = abs(g[i][j] - g[i + 1][j]);
int db = abs(b[i][j] - b[i + 1][j]);
if (min({dr, dg, db}) < 30) {
uf.unite(i * w + j, i * w + j + w);
}
}
}
int cnt = 0;
for (int i = 0; i < h * w; i++) {
if (uf.get(i) == i) {
cnt++;
}
}
double ratio = 1.0 * cnt / (h * w);
debug(ratio);
if (ratio < 0.0001) {
return 4;
}
if (ratio > 0.02) {
return 3;
}
cnt = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (min({r[i][j], g[i][j], b[i][j]}) > 220) {
cnt++;
}
}
}
ratio = 1.0 * cnt / (h * w);
debug(ratio);
if (ratio > 0.1) {
return 1;
}
cnt = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (max({r[i][j], g[i][j], b[i][j]}) < 20) {
cnt++;
}
}
}
debug(ratio);
if (ratio > 0.01) {
return 1;
}
return 2;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
int r[500][500];
int g[500][500];
int b[500][500];
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cin >> r[i][j] >> g[i][j] >> b[i][j];
}
}
cout << style(h, w, r, g, b) << '\n';
return 0;
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |