Submission #955247

#TimeUsernameProblemLanguageResultExecution timeMemory
955247Programmer123Art Class (IOI13_artclass)C++17
25 / 100
83 ms18004 KiB
#include "artclass.h" #include <bits/stdc++.h> struct pixel { double r, g, b; double h, s, l; pixel() { r = g = b = h = s = l = 0.0; } pixel(int _r, int _g, int _b) { r = _r / 255.0; g = _g / 255.0; b = _b / 255.0; auto xmax = std::max({r, g, b}); auto xmin = std::min({r, g, b}); auto c = xmax - xmin; l = (xmax + xmin) / 2; if (xmax == 0) { s = 0; } else { s = c / xmax; } if (c == 0.0) { h = 0; } else if (xmax == r) { h = 60.0 * (fmod(60.0 + ((g - b) / c), 6.0)); } else if (xmax == g) { h = 60.0 * ((b - r) / c + 2.0); } else if (xmax == b) { h = 60.0 * ((r - g) / c + 4.0); } else { assert(false); } } }; bool green(int r, int g, int b) { return (g > 100 && r < 100 && b < 100) || (g > 50 && r < 50 && b < 50); } double dist(pixel _a, pixel _b) { auto r = _a.r - _b.r; auto g = _a.g - _b.g; auto b = _a.b - _b.b; return std::sqrt(r * r + g * g + b * b); } double noise(std::vector<pixel> pixels) { double res = 0; for (int i = 0; i < pixels.size(); ++i) { for (int j = i + 1; j < pixels.size(); ++j) { res += dist(pixels[i], pixels[j]); } } return res; } int style(int H, int W, int R[500][500], int G[500][500], int B[500][500]) { std::mt19937 Rand(std::random_device{}()); auto data = new pixel *[H]; for (int i = 0; i < H; ++i) { data[i] = new pixel[W]; for (int j = 0; j < W; ++j) { data[i][j] = pixel(R[i][j], G[i][j], B[i][j]); } } int numG = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { numG += (std::abs(data[i][j].h - 120.0) < 10.0) && (data[i][j].l < 0.8) && (data[i][j].l > 0.2); } } std::map<int, int> diffs; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (data[i][j].l < 0.2 || data[i][j].l > 0.8) continue; int num = std::floor(data[i][j].h / 10); diffs[num]++; } } int numlarge = 0; for (auto [a, b]: diffs) { //#ifdef LOCAL // std::cout << "Colour " << a << ": " << b << std::endl; //#endif if (b > H * W / 4) numlarge++; } if (numG > 2100) return 2; int numW = 0; for (int i = 0; i < H; ++i) { for (int j = 0; j < W; ++j) { if (data[i][j].l > 0.8) numW++; } } if (numW > H * W / 4) return 1; double Noise = 0.0; int rad = 10; for (int sample = 0; sample < 100; ++sample) { int r = Rand() % H; int c = Rand() % W; while (r - rad < 0 || r + rad >= H) { r = Rand() % H; } while (c - rad < 0 || c + rad >= W) { c = Rand() % W; } std::vector<pixel> pixels; for (int i = r - rad; i <= r + rad; ++i) { for (int j = c - rad; j <= c + rad; ++j) { pixels.push_back(data[i][j]); } } Noise += noise(pixels); } if (Noise >= 1000000) return 3; return 4; }

Compilation message (stderr)

artclass.cpp: In function 'double noise(std::vector<pixel>)':
artclass.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pixel>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < pixels.size(); ++i) {
      |                     ~~^~~~~~~~~~~~~~~
artclass.cpp:47:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<pixel>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int j = i + 1; j < pixels.size(); ++j) {
      |                             ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...