Submission #97806

#TimeUsernameProblemLanguageResultExecution timeMemory
97806georgerapeanuArt Class (IOI13_artclass)C++11
73 / 100
316 ms13660 KiB
#include "artclass.h" #include <cstdio> #include <set> #include <algorithm> #include <queue> using namespace std; const int dx[] = {-1,0,1,0}; const int dy[] = {0,1,0,-1}; set<pair<pair<int,int>,int> > s; bool viz[500][500]; double abs_gr(int a){ if(a <= 255 / 2.0){ a = 255 - a; } const double split = 200; const double split_val = 0.50; if(a <= split) return a / (split / split_val); return split_val + (1 - split_val) * (a - split) / (255 - split); } int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) { double averageR = 0; double averageG = 0; double averageB = 0; double area = 0; double absolutes = 0; for(int i = 0;i < H;i++){ for(int j = 0;j < W;j++){ s.insert(make_pair(make_pair(R[i][j],G[i][j]),B[i][j])); averageR += R[i][j]; averageG += G[i][j]; averageB += B[i][j]; absolutes += abs_gr(R[i][j]) * abs_gr(G[i][j]) * abs_gr(B[i][j]); } } absolutes /= H; absolutes /= W; averageR /= H; averageR /= W; averageR /= 255.0; averageG /= H; averageG /= W; averageG /= 255.0; averageB /= H; averageB /= W; averageB /= 255.0; double average = (averageR + averageG + averageB) / 3.0; double averageRGB = (0.20 * averageR + 0.55 * averageG + 0.25 * averageB); int num = s.size(); int comp = 0; const int delta = 30; for(int i = 0;i < H;i++){ for(int j = 0;j < W;j++){ if(viz[i][j] == false){ queue< pair<int,int> > q; q.push({i,j}); viz[i][j] = true; comp++; while(!q.empty()){ int x = q.front().first; int y = q.front().second; q.pop(); for(int k = 0;k < 4;k++){ int xx = x + dx[k]; int yy = y + dy[k]; if(xx < 0 || xx >= H || yy < 0 || yy >= W || viz[xx][yy]){ continue; } if(abs(R[x][y] - R[xx][yy]) + abs(G[x][y] - G[xx][yy]) + abs(B[x][y] - B[xx][yy]) <= delta){ viz[xx][yy] = true; q.push({xx,yy}); } } } } } } if(comp <= 400){ return 4; } else{ if(comp >= 35000 && (double)num / comp <= 1.85){ return 3; } else{ if(average >= 0.55){ return 1; } else{ return 2; } } } printf("%d ",num); printf("%d ",comp); printf("%.6f ",average); printf("%.6f ",averageR); printf("%.6f ",averageG); printf("%.6f ",averageB); printf("%.6f ",averageRGB); printf("%.6f ",absolutes); printf("%.6f ",(double)num / comp); return -1; }

Compilation message (stderr)

artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:31:12: warning: unused variable 'area' [-Wunused-variable]
     double area = 0;
            ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...