제출 #658002

#제출 시각아이디문제언어결과실행 시간메모리
658002cristi_a미술 수업 (IOI13_artclass)C++17
60 / 100
83 ms6272 KiB
#include <bits/stdc++.h> #include "artclass.h" using namespace std; int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) { int area = H * W; int nonclr = 0; int green = 0; for(int i=0; i<H; i++) for(int j=0; j<W; j++) { int r = R[i][j], g = G[i][j], b = B[i][j]; if(abs(r-g) < 13 and abs(r-b) < 13 and abs(b-g) < 13) nonclr++; if(g - r >= 5 and g - b >= 5) green++; } double non_color_percent = ((1.00 * nonclr) / (1.00 * area)) * 100.00; double green_percent = (1.00 * green) / (1.00 * area) * 100.00; static const int sigmaB = 90; static const int sigmaN = 110; static const int dx[] = {0, 0, -1, 1}; static const int dy[] = {1, -1, 0, 0}; auto in = [&](int a, int b) { if(a < 0 or a >= H or b < 0 or b >= W) return false; return true; }; bool viz[500][500]; auto BFS = [&](int sigma) { for(int i=0; i<H; i++) for(int j=0; j<W; j++) viz[i][j] = false; queue<pair<int, int>> q; int cnt = 0; for(int i=0; i<H; i++) for(int j=0; j<W; j++) { if(viz[i][j]) continue; cnt++; q.emplace(i, j); viz[i][j] = true; while(q.empty() == false) { int x, y; tie(x, y) = q.front(); q.pop(); for(int k=0; k<4; k++) { int nx = x + dx[k]; int ny = y + dy[k]; if(!in(nx, ny) or viz[nx][ny]) continue; int dif = abs(R[x][y] - R[nx][ny]) + abs(G[x][y] - G[nx][ny]) + abs(B[x][y] - B[nx][ny]); if(dif <= sigma) { q.emplace(nx, ny); viz[nx][ny] = true; } } } } return cnt; }; int blocks = BFS(sigmaB); int nuances = BFS(sigmaN); /*cout << "blocks: " << blocks << "\n"; cout << "nuances: " << nuances << "\n"; cout << "non_color: " << non_color_percent << "\n"; cout << "green: " << green_percent << "\n"; cout << "green: " << green << "\n";*/ if(blocks <= 130 and non_color_percent >= 30.00) return 1; if(non_color_percent >= 60.00 and blocks <= 3000) return 1; if(green_percent >= 26.00) return 2; if(nuances <= 50) return 4; return 3; }
#Verdict Execution timeMemoryGrader output
Fetching results...