Submission #259839

#TimeUsernameProblemLanguageResultExecution timeMemory
259839SamAndArt Class (IOI13_artclass)C++17
84 / 100
107 ms6524 KiB
#include"artclass.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 503;
const int xx[4] = {0, 1, 0, -1};
const int yy[4] = {1, 0, -1, 0};

double ans;

int n, m;

int r[N][N], g[N][N], b[N][N];

bool c[N][N];
void bfs(int x, int y)
{
    queue<pair<int, int> > q;
    c[x][y] = true;
    q.push(m_p(x, y));
    while (!q.empty())
    {
        x = q.front().first;
        y = q.front().second;
        q.pop();
        for (int i = 0; i < 4; ++i)
        {
            int hx = x + xx[i];
            int hy = y + yy[i];
            if (hx >= 0 && hx < n && hy >= 0 && hy < m && !c[hx][hy])
            {
                int u = 0;
                u += abs(r[x][y] - r[hx][hy]);
                u += abs(g[x][y] - g[hx][hy]);
                u += abs(b[x][y] - b[hx][hy]);
                if (u < 50)
                {
                    c[hx][hy] = true;
                    q.push(m_p(hx, hy));
                }
            }
        }
    }
}

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500])
{
    memset(c, false, sizeof c);
    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];
        }
    }

    double gg = 0;
    for (int i = 0; i < n - 1; ++i)
    {
        for (int j = 0; j < m - 1; ++j)
        {
            gg += abs(R[i][j] - R[i][j + 1]);
            gg += abs(R[i][j] - R[i + 1][j]);
            gg += abs(G[i][j] - G[i][j + 1]);
            gg += abs(G[i][j] - G[i + 1][j]);
            gg += abs(B[i][j] - B[i][j + 1]);
            gg += abs(B[i][j] - B[i + 1][j]);
        }
    }
    gg /= (n * m);

    double q = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            if (!c[i][j])
            {
                q += 1;
                bfs(i, j);
            }
        }
    }
    q /= (n * m);
    q *= 10000;

    if (q < 2)
        return 4;
    if (q < 50)
        return 1;
    if (q < 2000)
        return 2;
    return 3;
}
#Verdict Execution timeMemoryGrader output
Fetching results...