#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");
}
Compilation message
artclass.cpp: In function 'int main()':
artclass.cpp:28:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d%d", &h, &w);
| ~~~~~^~~~~~~~~~~~~~~~
artclass.cpp:32:66: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", r[i] + j);
| ~~~~~^~~~~~~~~~~~~~~~
artclass.cpp:33:66: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", g[i] + j);
| ~~~~~^~~~~~~~~~~~~~~~
artclass.cpp:34:66: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", b[i] + j);
| ~~~~~^~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccvssqbd.o: in function `main':
artclass.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPkfTJc.o:grader.c:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccPkfTJc.o: in function `main':
grader.c:(.text.startup+0x200): undefined reference to `style'
collect2: error: ld returned 1 exit status