# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
534300 | benson1029 | Art Class (IOI13_artclass) | C++14 | 85 ms | 11148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |