# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
443765 | mjhmjh1104 | Art Class (IOI13_artclass) | C++17 | 0 ms | 0 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cmath>
#include <cstdio>
#include <vector>
#include <numeric>
#include <utility>
using namespace std;
const int DIV = 120;
int h, w, r[506][506], g[506][506], b[506][506];
double averageR, averageG, averageB, deviation, dispersion, grayscale;
const pair<double, double> blue[5] = { { 0, 5.5 }, { 128, 5.5 }, { 128, 29 }, { 0, 29 }, { 0, 5.5 } };
const pair<double, double> red[5] = { { 128, 5.5 }, { 256, 5.5 }, { 256, 29 }, { 128, 29 }, { 128, 5.5 } };
double cross(double x1, double y1, double x2, double y2) {
return x1 * y2 - x2 * y1;
}
int ccw(pair<double, double> a, pair<double, double> b, pair<double, double> c) {
double t = cross(b.first - a.first, b.second - a.second, c.first - a.first, c.second - a.second);
if (t > 0) return 1;
if (t < 0) return -1;
return 0;
}
int main() {
scanf("%d%d", &h, &w);
fill(r[0], r[h - 1] + w, 0);
fill(g[0], g[h - 1] + w, 0);
fill(b[0], b[h - 1] + w, 0);
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", r[i] + j);
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", g[i] + j);
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", b[i] + j);
averageR = accumulate(r[0], r[h - 1] + w, 0LL) / (double)(h * w);
averageG = accumulate(g[0], g[h - 1] + w, 0LL) / (double)(h * w);
averageB = accumulate(b[0], b[h - 1] + w, 0LL) / (double)(h * w);
int rd = min(h, w) / DIV;
vector<double> v;
for (int i = 0; i < DIV; i++) for (int j = 0; j < DIV; j++) {
int x = h * i / DIV, y = w * j / DIV;
vector<double> _r, _g, _b;
for (int i = x - rd; i <= x + rd; i++) for (int j = y - rd; j <= y + rd; j++) {
if (i < 0 || i >= h || j < 0 || j >= w) continue;
_r.push_back(r[i][j]); _g.push_back(g[i][j]); _b.push_back(b[i][j]);
}
double avR = accumulate(_r.begin(), _r.end(), 0.) / (int)_r.size();
double avG = accumulate(_g.begin(), _g.end(), 0.) / (int)_g.size();
double avB = accumulate(_b.begin(), _b.end(), 0.) / (int)_b.size();
for (auto &i: _r) i = (i - avR) * (i - avR);
for (auto &i: _g) i = (i - avG) * (i - avG);
for (auto &i: _b) i = (i - avB) * (i - avB);
v.push_back(accumulate(_r.begin(), _r.end(), 0.) / (int)_r.size());
v.back() = sqrt(v.back());
v.push_back(accumulate(_g.begin(), _g.end(), 0.) / (int)_g.size());
v.back() = sqrt(v.back());
v.push_back(accumulate(_b.begin(), _b.end(), 0.) / (int)_b.size());
v.back() = sqrt(v.back());
}
dispersion = accumulate(v.begin(), v.end(), 0.) / (int)v.size();
grayscale = 0.2989 * averageR + 0.5870 * averageG + 0.1140 * averageB;
if (dispersion < 5.5) return puts("4"), 0;
int cnt = 0;
for (int i = 0; i < 4; i++) cnt += ccw(blue[i], blue[i + 1], pair{ grayscale, dispersion });
if (cnt == 4) return puts("2"), 0;
cnt = 0;
for (int i = 0; i < 4; i++) cnt += ccw(red[i], red[i + 1], pair{ grayscale, dispersion });
if (cnt == 4) return puts("1"), 0;
puts("3");
}