제출 #940647

#제출 시각아이디문제언어결과실행 시간메모리
940647Der_Vlapos미술 수업 (IOI13_artclass)C++17
0 / 100
57 ms11380 KiB
#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 timeMemoryGrader output
Fetching results...