Submission #554097

#TimeUsernameProblemLanguageResultExecution timeMemory
554097elazarkorenArt Class (IOI13_artclass)C++17
12 / 100
56 ms3268 KiB
#include "artclass.h" #include <bits/stdc++.h> #define x first #define y second #define chkmin(a, b) a = min(a, b) #define chkmax(a, b) a = max(a, b) #define all(v) v.begin(), v.end() using namespace std; typedef long long ll; typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pii> vii; const int infinity = 1e9; struct Style{ int red, green, blue, gray; Style() {} Style(int r, int g, int b, int gr): red(r), green(g), blue(b), gray(gr) {} int Close(int r, int g, int b, int gr) { return abs(r - red) + abs(g - green) + abs(b - blue) + abs(gr - gray); } }; Style s[] = {Style(), Style(146, 166, 146, 167), Style(67, 97, 63, 87), Style(106, 128, 106, 124), Style(54, 89, 54, 100)}; int cnt[5]; void ClosestR(int x) { int ans = infinity; for (int i = 1; i <= 4; i++) { chkmin(ans, abs(x - s[i].red)); } for (int i = 1; i <= 4; i++) { if (abs(x - s[i].red) == ans) { cnt[i]++; } } } void ClosestG(int x) { int ans = infinity; for (int i = 1; i <= 4; i++) { chkmin(ans, abs(x - s[i].green)); } for (int i = 1; i <= 4; i++) { if (abs(x - s[i].green) == ans) { cnt[i]++; } } } void ClosestB(int x) { int ans = infinity; for (int i = 1; i <= 4; i++) { chkmin(ans, abs(x - s[i].blue)); } for (int i = 1; i <= 4; i++) { if (abs(x - s[i].blue) == ans) { cnt[i]++; } } } void ClosestGr(int x) { int ans = infinity; for (int i = 1; i <= 4; i++) { chkmin(ans, abs(x - s[i].gray)); } for (int i = 1; i <= 4; i++) { if (abs(x - s[i].gray) == ans) { cnt[i]++; } } } int style(int h, int w, int r[500][500], int g[500][500], int b[500][500]) { ll sum_r = 0, sum_g = 0, sum_b = 0, gray_scale = 0; for (int i = 0; i < h; i++) { for (int j = 0; j < w; j++) { sum_r += r[i][j], sum_g += g[i][j], sum_b += b[i][j]; gray_scale += (r[i][j] + g[i][j] + b[i][j]) / 3; } } sum_r /= (h * w); sum_g /= (h * w); sum_b /= (h * w); gray_scale /= (h * w); cnt[1] = cnt[2] = cnt[3] = cnt[4] = 0; ClosestR(sum_r), ClosestG(sum_g), ClosestB(sum_b), ClosestGr(gray_scale); int max_cnt = 0; for (int i = 1; i <= 4; i++) { chkmax(max_cnt, cnt[i]); } pii ans = {infinity, 0}; for (int i = 1; i <= 4; i++) { if (cnt[i] == max_cnt) { pii q = {s[i].Close(sum_r, sum_g, sum_b, gray_scale), i}; chkmin(ans, q); } } return ans.y; }
#Verdict Execution timeMemoryGrader output
Fetching results...