Submission #1155522

#TimeUsernameProblemLanguageResultExecution timeMemory
1155522alexddArt Class (IOI13_artclass)C++20
9 / 100
39 ms19344 KiB
#include "artclass.h"
#include<bits/stdc++.h>
using namespace std;
int dx[4] = {-1,1,0,0};
int dy[4] = {0,0,-1,1};

int H,W;
int R[505][505],G[505][505],B[505][505];
bool is_green()
{
    int cnt=0;
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            //if(G[i][j] >= max(R[i][j], B[i][j])) cnt++;
            if(2*G[i][j] >= R[i][j] + B[i][j]) cnt++;
        }
    }
    if(cnt >= H*W/2)
        return 1;
    return 0;
}
bool visited[505][505];
bool similar(int ax, int ay, int bx, int by)
{
    if(abs(R[ax][ay]-R[bx][by]) + abs(G[ax][ay]-G[bx][by]) + abs(B[ax][ay]-B[bx][by]) <= 30)
        return 1;
    return 0;
}
void dfs(int x, int y)
{
    visited[x][y]=1;
    for(int v=0;v<4;v++)
    {
        int newx = x+dx[v], newy = y+dy[v];
        if(newx>=1 && newx<=H && newy>=1 && newy<=W && !visited[newx][newy] && similar(x,y,newx,newy))
            dfs(newx,newy);
    }
}
int nr_zones()
{
    int cnt=0;
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            if(!visited[i][j])
            {
                cnt++;
                dfs(i,j);
            }
        }
    }
    return cnt;
}
int style(int cit_H, int cit_W, int cit_R[500][500], int cit_G[500][500], int cit_B[500][500])
{
    H = cit_H;
    W = cit_W;
    for(int i=1;i<=H;i++)
    {
        for(int j=1;j<=W;j++)
        {
            R[i][j] = cit_R[i-1][j-1];
            G[i][j] = cit_G[i-1][j-1];
            B[i][j] = cit_B[i-1][j-1];
        }
    }
    if(is_green())
        return 2;
    int nrz = nr_zones();
    if(nrz <= 700)
        return 4;
    if(nrz >= 40000)
        return 3;
    return 1;
}
#Verdict Execution timeMemoryGrader output
Fetching results...