# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
413599 | KoD | 미술 수업 (IOI13_artclass) | C++17 | 94 ms | 10604 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "artclass.h"
template <class T> using Vec = std::vector<T>;
struct UnionFind {
Vec<int> par;
int comp;
UnionFind(const int n): par(n, -1), comp(n) {}
int find(const int u) {
return par[u] < 0 ? u : par[u] = find(par[u]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if (x == y) {
return;
}
if (par[x] > par[y]) {
std::swap(x, y);
}
par[x] += par[y];
par[y] = x;
comp -= 1;
}
};
int solve(const int N, const Vec<int> R, const Vec<int> G, const Vec<int> B, const std::array<int, 4> D) {
UnionFind dsu(N);
for (int i = 0; i < N; ++i) {
for (int k = 0; k < 4; ++k) {
const auto j = i + D[k];
if (0 <= j and j < N) {
if (std::abs(R[i] - R[j]) <= 20 and std::abs(G[i] - G[j]) <= 20 and std::abs(B[i] - B[j]) <= 20) {
dsu.merge(i, j);
}
}
}
}
int white = 0;
for (int i = 0; i < N; ++i) {
if (R[i] >= 200 and G[i] >= 200 and B[i] >= 200) {
white += 1;
}
}
if ((double) white / N >= 0.3) {
return 1;
}
if ((double) dsu.comp / N >= 0.19) {
return 3;
}
if ((double) dsu.comp / N <= 0.0003) {
return 4;
}
if ((double) white / N >= 0.1 and (double) dsu.comp / N >= 0.1) {
return 3;
}
if ((double) dsu.comp / N <= 0.006) {
return 4;
}
// std::cerr << std::fixed << std::setprecision(10);
// std::cerr << (double) dsu.comp / N << ' ' << (double) white / N << std::endl;
return 2;
}
int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
const int N = H * W;
Vec<int> r(N), g(N), b(N);
for (int i = 0; i < H; ++i) {
for (int j = 0; j < W; ++j) {
r[i * W + j] = R[i][j];
g[i * W + j] = G[i][j];
b[i * W + j] = B[i][j];
}
}
return solve(N, r, g, b, std::array<int, 4>{W, 1, -W, -1});
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |