Submission #584774

#TimeUsernameProblemLanguageResultExecution timeMemory
584774benson1029Art Class (IOI13_artclass)C++14
91 / 100
79 ms21836 KiB
#include "artclass.h" #include <bits/stdc++.h> using namespace std; int h,w; bool vis[500][500]; int v[500][500][3]; double avg[500][500][3]; int dx[4] = {0, 0, 1, -1}; int dy[4] = {1, -1, 0, 0}; bool valid(int x, int y) { return (x>=0&&y>=0&&x<h&&y<w); } bool near(int X1, int Y1, int X2, int Y2) { return (abs(v[X1][Y1][0]-v[X2][Y2][0]) + abs(v[X1][Y1][1]-v[X2][Y2][1]) + abs(v[X1][Y1][2]-v[X2][Y2][2])) <= 30; } bool near2(int X1, int Y1, int X2, int Y2) { return (abs(v[X1][Y1][0]-v[X2][Y2][0]) + abs(v[X1][Y1][1]-v[X2][Y2][1]) + abs(v[X1][Y1][2]-v[X2][Y2][2])) <= 10; } void dfs(int x, int y) { vis[x][y] = true; for(int i=0; i<4; i++) { if(!valid(x+dx[i], y+dy[i])) continue; if(vis[x+dx[i]][y+dy[i]]) continue; if(near(x, y, x+dx[i], y+dy[i])) { dfs(x+dx[i], y+dy[i]); } } } 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++) { v[i][j][0] = R[i][j]; v[i][j][1] = G[i][j]; v[i][j][2] = B[i][j]; } int connected_component = 0; for(int i=0; i<h; i++) for(int j=0; j<w; j++) { if(!vis[i][j]) { dfs(i, j); connected_component++; } } if(connected_component <= 500) return 4; double r,g,b; int cntg = 0; for(int i=0; i<h; i++) for(int j=0; j<w; j++) { r += R[i][j]; g += G[i][j]; b += B[i][j]; if(G[i][j]-50 > B[i][j] && G[i][j]+10 > R[i][j]) cntg++; } if(g > r && g > b) cntg += 100000; int cntsame = 0; for(int i=0; i<h; i++) { for(int j=0; j<w; j++) { if(i>=3 && near2(i, j, i-3, j)) cntsame++; if(j>=3 && near2(i, j, i, j-3)) cntsame++; } } if(cntg > 10000) return 2; if(cntsame>100000) return 1; return 3; }

Compilation message (stderr)

artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:59:5: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |     if(g > r && g > b) cntg += 100000;
      |     ^~
artclass.cpp:59:5: warning: 'g' may be used uninitialized in this function [-Wmaybe-uninitialized]
artclass.cpp:59:14: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |     if(g > r && g > b) cntg += 100000;
      |        ~~~~~~^~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...