Submission #170806

#TimeUsernameProblemLanguageResultExecution timeMemory
170806AlexLuchianovArt Class (IOI13_artclass)C++14
89 / 100
344 ms14244 KiB
#include "artclass.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <set>
#include <cmath>

using ll = long long;
using ld = long double;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

bool isgreen(int red, int green, int blue){
  return red + 20 <= green && blue + 20 <= green ;
}

bool isred(int red, int green, int blue){
  return 150 <= red && 50 <= green && 50 <= blue;
}
bool isblue(int red, int green, int blue){
  return 50 <= red && 50 <= green && 150 <= blue;
}

int const whitethreshold = 530;

bool iswhite(int red, int green, int blue){
  return whitethreshold <= red + green + blue;
}

int const nmax = 500;
int black[1 + nmax][1 + nmax];
int up[1 + nmax];

int red[1 + nmax][1 + nmax];
int green[1 + nmax][1 + nmax];
int blue[1 + nmax][1 + nmax];

int dif(int x, int y, int x2, int y2){
  return fabs(red[x][y] - red[x2][y2]) +
         fabs(green[x][y] - green[x2][y2]) +
         fabs(blue[x][y] - blue[x2][y2]);
}

int biggestrectangle(int n, int m){
  int result = 0;
  for(int j = 0; j < m; j++)
    up[j] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++){
      if(black[i][j] == 1 && (i == 0 || dif(i, j, i - 1, j) <= 50))
        up[j]++;
      else
        up[j] = 0;
    }
    for(int j = 0; j < m; j++) {
      int smin = up[j];
      for(int j2 = j; j2 < m; j2++) {
        smin = MIN(smin, up[j2]);
        result = MAX(result, smin * (j2 - j + 1));
      }
    }
  }
  return result;
}

int white[1 + nmax][1 + nmax];

int biggestrectanglewhite(int n, int m){
  int result = 0;
  for(int j = 0; j < m; j++)
    up[j] = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++){
      if(white[i][j] == 1 && (i == 0 || dif(i, j, i - 1, j) <= 50))
        up[j]++;
      else
        up[j] = 0;
    }
    for(int j = 0; j < m; j++) {
      int smin = up[j];
      for(int j2 = j; j2 < m; j2++) {
        smin = MIN(smin, up[j2]);
        result = MAX(result, smin * (j2 - j + 1));
      }
    }
  }
  return result;
}

std::set<int> used;

bool cross(int x, int y, int sz, int n, int m){
  if(0 <= x - sz && x + sz <= n && 0 <= y - sz && y + sz <= m) {

    for(int y2 = y - sz; y2 <= y + sz; y2++)
      if(20 < dif(x, y, x, y2))
        return 0;
    for(int x2 = x - sz; x2 <= x + sz; x2++)
      if(20 < dif(x, y, x2, y))
        return 0;
    return 20 < dif(x, y, x + sz, y + sz) &&
           20 < dif(x, y, x + sz, y - sz) &&
           20 < dif(x, y, x - sz, y + sz) &&
           20 < dif(x, y, x - sz, y - sz)
    ;
  } else
    return 0;
}

int value[1 + nmax][1 + nmax];

int style(int n, int m, int R[nmax][nmax], int G[nmax][nmax], int B[nmax][nmax]) {
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++) {
      red[i][j] = R[i][j];
      green[i][j] = G[i][j];
      blue[i][j] = B[i][j];
    }

  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      value[i][j] = (red[i][j] + green[i][j] + blue[i][j]) / 3;
  int result = 0;

  for(int i = 0;i < n; i++)
    for(int j = 0; j < m - 1; j++)
      result += fabs(value[i][j] - value[i][j + 1]);

  for(int i = 0; i < n - 1; i++)
    for(int j = 0; j < m; j++)
      result += fabs(value[i][j] - value[i + 1][j]);

  std::ofstream out ("artclass.txt");
  ld totalgreen = 0, totaltotal = 0;
  //out << n << " " << m << '\n';

  used.clear();

  int crosses = 0;

  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
      crosses += cross(i, j, 20, n, m);

  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++) {
      black[i][j] = (0 == iswhite(R[i][j], G[i][j], B[i][j]));
      white[i][j] = iswhite(R[i][j], G[i][j], B[i][j]);
      used.insert((R[i][j]<<16) |
                  (G[i][j]<<8)  |
                  (B[i][j])       );
    }
  /*
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++)
      if(isgreen(R[i][j], G[i][j], B[i][j]) == 1)
        out << " ";
      else
        out << "#";
    out << '\n';
  }
  */

  //*
  for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++) {
      totalgreen += isgreen(R[i][j], G[i][j], B[i][j]);
    }
  //*/

  /*
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < m; j++)
      if(iswhite(R[i][j], G[i][j], B[i][j]))
        out << " ";
      else
        out << "#";
    out << '\n';
  }
  */

  ld blackpercent = ((double)biggestrectangle(n, m)) / (n * m);
  ld whitepercent = ((double)biggestrectanglewhite(n, m)) / (n * m);
  ld greenpercent = ((double)totalgreen) / (n * m);
  ld distribution = ((double)used.size()) / (n * m);
  ld variation = ((double)result) / (n * m);

  /*
  std::cerr << "Average variation " << ((double)result) / (n * m) << '\n';
  std::cerr << "Crosses:" << crosses << '\n';
  std::cerr << "Black rectangle: " << blackpercent << '\n';
  std::cerr << "Green: " << std::setprecision(6) << std::fixed << greenpercent << '\n';
  std::cerr << "White rectangle: " << whitepercent << '\n';
  std::cerr << "Distribution: " << distribution << '\n';
  //*/

  int points[5] = {0};

  points[2] = 1;

  if(2 <= crosses){
    points[1] += 10;
    points[4] += 10;
  }

  if(0.2 <= blackpercent)
    points[4] += 10;
  else if(0.1 <= blackpercent)
    points[4] += 7;

  if(0.1 <= whitepercent )
    points[1] += 5;
  else if(0.01 <= whitepercent)
    points[1] += 2;

  if(blackpercent <= 0.0009 && whitepercent <= 0.0009)
    points[3] += 8;
  else if(blackpercent <= 0.003 && whitepercent <= 0.003)
    points[3] += 6;


  if(0.1 <= greenpercent)
    points[2] += 7;
  else if(0.05 <= greenpercent)
    points[2] += 4;

  if(0.6 <= distribution)
    points[3] += 8;
  else if(0.3 <= distribution){
    points[2] += 4;
    points[3] += 4;
  }
  if(distribution <= 0.2) {
    points[2] -= 7;
    points[3] -= 7;
  }

  if(variation <= 5)
    points[4] += 10;
  else if(variation <=  16)
    points[1] += 3;
  else if(variation <= 30)
    points[2] += 3;
  else
    points[3] += 10;
  int smax = 0;
  for(int i = 1;i <= 4; i++)
    smax = MAX(smax, points[i]);

  //std::cout << smax << '\n';

  for(int i = 1;i <= 4; i++)
    if(smax == points[i])
      return i;
  return 2;
}

Compilation message (stderr)

artclass.cpp: In function 'int style(int, int, int (*)[500], int (*)[500], int (*)[500])':
artclass.cpp:134:22: warning: unused variable 'totaltotal' [-Wunused-variable]
   ld totalgreen = 0, totaltotal = 0;
                      ^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...