Submission #534300

#TimeUsernameProblemLanguageResultExecution timeMemory
534300benson1029Art Class (IOI13_artclass)C++14
7 / 100
85 ms11148 KiB
#include "artclass.h"
#include<bits/stdc++.h>
using namespace std;

bool vis[500][500];
int r[500][500], g[500][500], b[500][500];
int cntcompo = 0;
stack< pair<int,int> > stk;
int h,w;

bool ok(int x, int y) {
    return (x>=0&&y>=0&&x<h&&y<w&&!vis[x][y]);
}

bool close(int X1, int Y1, int X2, int Y2) {
    int absdiff = abs(r[X1][Y1]-r[X2][Y2]) + abs(g[X1][Y1]-g[X2][Y2]) + abs(b[X1][Y1]-b[X2][Y2]);
    if(absdiff < 50) {
        return true;
    } else return false;
}

void dfs(int x, int y) {
    stk.push({x, y});
    while(!stk.empty()) {
        int x = stk.top().first;
        int y = stk.top().second;
        vis[x][y] = true;
        stk.pop();
        if(ok(x+1, y) && close(x, y, x+1, y)) stk.push({x+1, y});
        if(ok(x-1, y) && close(x, y, x-1, y)) stk.push({x-1, y});
        if(ok(x, y+1) && close(x, y, x, y+1)) stk.push({x, y+1});
        if(ok(x, y-1) && close(x, y, x, y-1)) stk.push({x, y-1});
    }
}

int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) {
    h=H; w=W;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            r[i][j] = R[i][j];
            g[i][j] = G[i][j];
            b[i][j] = B[i][j];
        }
    }
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            if(!vis[i][j]) {
                dfs(i,j);
                cntcompo++;
            }
        }
    }
    if(cntcompo<100) return 4;
    else if(cntcompo<30000) return 1;
    else return 2;
}
#Verdict Execution timeMemoryGrader output
Fetching results...