제출 #170787

#제출 시각아이디문제언어결과실행 시간메모리
170787AlexLuchianov미술 수업 (IOI13_artclass)C++14
0 / 100
308 ms15608 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;

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];
    }

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

  used.clear();

  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);
  //std::cout << "Black rectangle: " << blackpercent << '\n';
  ld greenpercent = ((double)totalgreen) / (n * m);
  ld distribution = ((double)used.size()) / (n * m);
  //*
  std::cout << "Green: " << std::setprecision(6) << std::fixed << greenpercent << '\n';
  std::cout << "White rectangle: " << whitepercent << '\n';
  std::cout << "Distribution: " << distribution << '\n';
  //*/

  int points[5] = {0};

  points[2] = 1;

  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.009 && whitepercent <= 0.009)
    points[3] += 3;

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

  if(0.3 <= distribution)
    points[1] -= 6;

  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;
}

컴파일 시 표준 에러 (stderr) 메시지

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