Submission #554080

#TimeUsernameProblemLanguageResultExecution timeMemory
554080elazarkorenArt Class (IOI13_artclass)C++17
18 / 100
59 ms6056 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 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);
    pii ans = {infinity, 0};
    for (int i = 1; i <= 4; i++) {
        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...