제출 #413601

#제출 시각아이디문제언어결과실행 시간메모리
413601KoD미술 수업 (IOI13_artclass)C++17
76 / 100
88 ms10764 KiB
#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, yellow = 0, red = 0; for (int i = 0; i < N; ++i) { if (R[i] >= 200 and G[i] >= 200 and B[i] >= 200) { white += 1; } if (R[i] >= 200 and G[i] >= 200) { yellow += 1; } if (R[i] >= std::max(G[i], B[i]) + 30) { red += 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; } 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 timeMemoryGrader output
Fetching results...