Submission #534312

#TimeUsernameProblemLanguageResultExecution timeMemory
534312benson1029Art Class (IOI13_artclass)C++14
34 / 100
88 ms8188 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 eps) { 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 < eps) { return true; } else return false; } bool close2(int X1, int Y1, int X2, int Y2, int eps) { if(abs(r[X1][Y1]-r[X2][Y2]) < eps && abs(g[X1][Y1]-g[X2][Y2]) < eps && abs(b[X1][Y1]-b[X2][Y2]) < eps) { return true; } else return false; } void dfs(int x, int y, int eps) { 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, eps)) stk.push({x+1, y}); if(ok(x-1, y) && close(x, y, x-1, y, eps)) stk.push({x-1, y}); if(ok(x, y+1) && close(x, y, x, y+1, eps)) stk.push({x, y+1}); if(ok(x, y-1) && close(x, y, x, y-1, eps)) stk.push({x, y-1}); } } void dfs2(int X, int Y, int eps) { 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) && close2(X, Y, x+1, y, eps)) stk.push({x+1, y}); if(ok(x-1, y) && close2(X, Y, x-1, y, eps)) stk.push({x-1, y}); if(ok(x, y+1) && close2(X, Y, x, y+1, eps)) stk.push({x, y+1}); if(ok(x, y-1) && close2(X, Y, x, y-1, eps)) 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++) vis[i][j] = false; for(int i=0; i<H; i++) { for(int j=0; j<W; j++) { if(!vis[i][j]) { dfs(i,j, 50); cntcompo++; } } } if(cntcompo<100) return 4; int speccolor = 0; for(int i=0; i<H; i++) { for(int j=0; j<W; j++) { if(r[i][j]>175 && g[i][j]<100 && b[i][j]<100) speccolor++; else if(b[i][j]>175 && r[i][j]<100 && g[i][j]<100) speccolor++; else if(r[i][j]>175 && g[i][j]>175 && b[i][j]<100) speccolor++; } } if(speccolor > 4000) return 1; int green = 0; for(int i=0; i<H; i++) { for(int j=0; j<W; j++) { if(g[i][j]-b[i][j]>10 && g[i][j]-r[i][j]>10) { green++; } else if(r[i][j]-g[i][j]<10 && g[i][j]-b[i][j]>30) green++; } } if(green > 3000) return 2; else return 3; }
#Verdict Execution timeMemoryGrader output
Fetching results...