제출 #170748

#제출 시각아이디문제언어결과실행 시간메모리
170748AlexLuchianov미술 수업 (IOI13_artclass)C++14
62 / 100
307 ms13020 KiB
#include "artclass.h"
#include <iostream>
#include <fstream>
#include <iomanip>
#include <set>

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 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)
        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)
        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]) {
  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.7 <= blackpercent)
    points[4] += 10;
  else if(0.3 <= blackpercent)
    points[4] += 5;
  else if(blackpercent <= 0.03)
    points[3] += 7;

  if(0.2 <= greenpercent)
    points[2] += 7;
  if(0.01 <= greenpercent)
    points[2] += 4;
  else if(greenpercent <= 0.00001)
    points[2] -= 5;

  if(0.05 <= greenpercent)
    points[4] -= 5;

  if(0.1 <= whitepercent)
    points[1] += 3;

  if(0.005 <= whitepercent)
    points[3] -= 5;

  if(0.32 <= distribution)
    points[2] += 2;

  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:82:22: warning: unused variable 'totaltotal' [-Wunused-variable]
   ld totalgreen = 0, totaltotal = 0;
                      ^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...