CSES - Datatähti 2024 alku - Results
Submission details
Task:Uolevin kalansaalis
Sender:rottis
Submission time:2023-11-12 22:16:59 +0200
Language:C++ (C++20)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int get_value(int, int, int, int, std::vector<int>*)':
input/code.cpp:83:23: error: array must be initialized with a brace-enclosed initializer
   83 |   for (int fish[3] : *fishies) {
      |                       ^~~~~~~
input/code.cpp:88:1: warning: no return statement in function returning non-void [-Wreturn-type]
   88 | }
      | ^
input/code.cpp: In function 'int main()':
input/code.cpp:95:21: error: type/value mismatch at argument 2 in template parameter list for 'template<class _Tp, class _Alloc> class std::vector'
   95 |   std::vector<int, 3> fishies;
      |                     ^
input/code.cpp:95:21: note:   expected a type, got '3'
input/code.cpp:98:16: error: redeclaration of 'int total'
   98 |   int y, x, t, total;
      |                ^~~~~
input/code.cpp:96:7: note: 'int total' previously declared here
   96 |   int total = 0;
      |       ^~~~~
input/code.cpp:103:32: error: expected ';' before 'fishies'
  103 |     t = ((ct == 'H') ?...

Code

/*def legal_triangle(y, x, size, dir, height, width) # dir = -1 or 1 # O(1)
  return x >= 0 &&
        (x + size) <= (width) && 
        (y + (dir * size) + 1) >= 0 &&
        (y + (dir * size)) <= height
end*/

#include <iostream>
#include <cmath>
#include <vector>

bool legal_triangle(int y, int x, int size, int dir, int height, int width) {
  return (x >= 0) &&
         ((x + size) <= width) &&
         ((y + (dir * size) + 1) >= 0) &&
         ((y + (dir * size)) <= height);
}

/*def in_triangle(tri_y, tri_x, tri_size, tri_dir, cell_y, cell_x) # O(1)
  tri_y2 = tri_y + tri_size * tri_dir
  offset = ((((tri_y) % 2 == 1) && ((cell_y) % 2 == 0)) ? -1 : 0)

  if tri_dir == 1 
    dy = (tri_y - cell_y) / 2.0
    dyl = dy.ceil.to_i
    dyr = dy.floor.to_i

    return (tri_y <= cell_y && cell_y < tri_y2) && # dir = 1   
    (tri_x - offset) <= (cell_x + dyl) && # both
    (cell_x + offset) < (tri_x + (tri_size + dyr)) # both
  else    
    dy = (cell_y - tri_y) / 2.0
    dyl = dy.ceil.to_i
    dyr = dy.floor.to_i

    return (tri_y2 <= cell_y && cell_y <= tri_y) && # dir = -1
    (tri_x - offset) <= (cell_x + dyl) && # both
    (cell_x + offset) < (tri_x + (tri_size + dyr)) # both
  end

end*/

bool in_triangle(int tri_y, int tri_x, int tri_size, int tri_dir, int cell_y, int cell_x) {
  int tri_y2 = tri_y + tri_size * tri_dir;
  int offset = ((((tri_y) % 2 == 1) && ((cell_y) % 2 == 0)) ? -1 : 0);
  float dy;
  int dyl, dyr;

  if (tri_dir == 1) {
    dy = (tri_y - cell_y) / 2.0;
    dyl = (int) ceil(dy);
    dyr = (int) floor(dy);

    return (tri_y <= cell_y && cell_y < tri_y2) &&
    (tri_x - offset) <= (cell_x + dyl) &&
    (cell_x + offset) < (tri_x + (tri_size + dyr));
  } else {
    dy = (cell_y - tri_y) / 2.0;
    dyl = (int) ceil(dy);
    dyr = (int) floor(dy);

    return (tri_y2 <= cell_y && cell_y <= tri_y) &&
    (tri_x - offset) <= (cell_x + dyl) &&
    (cell_x + offset) < (tri_x + (tri_size + dyr));
  }
}

/*
def get_value(y, x, size, dir, fishies)
  val = 0
  fishies.each do |fish|
    if in_triangle(y, x, size, dir, fish[0], fish[1])
      val += fish[2]
      #print("#{fish} is in tri")
    end
  end
  return val # total - val for true value 
end
*/

int get_value(int y, int x, int size, int dir, std::vector<int> *fishies) {
  int val = 0;
  for (int fish[3] : *fishies) {
    if (in_triangle(y, x, size, dir, fish[0], fish[1])) {
      val += fish[2];
    }
  }
}

int main() {
  int height, width, count;
  
  std::cin >> height >> width >> count;

  std::vector<int, 3> fishies;
  int total = 0;
  int min_size = ((height <= 10) ? 1 : 10);
  int y, x, t, total;
  char ct;

  for (int i = 0; i < count; i++) {
    std::cin >> y >> x >> ct;
    t = ((ct == 'H') ? 1 : -10)
    fishies.push_back([y - 1, x - 1, t]);
    total += t;
  }
  
  int size, dir;
  bool legal;
  int max_value = 0;
  int value;

  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      size = min_size;
      dir = -1;
      c = true;
      while (c) {
        legal = legal_triangle(y, x, size, dir, height, width);
        if (legal) {
          value = get_value(y, x, size, dir, *fishies);
          if (max_value < value) {
            max_value = value;
          }
          size += 1;
        } else {
          if (dir == -1) {
            size = min_size;
            dir = 1;
          } else {
            c = false;
          }
        } 
      }
    }
  }
  std::cout << total - max_value;
  return 0;
}
/*
height, width, count = gets.chomp.split(" ").map(&:to_i)
fishies = []
total = 0
min_size = (height <= 10 ? 1 : 10)

count.times do
  y, x, t = gets.chomp.split(" ")
  t = (t == "H" ? 1 : -10)
  fishies << [y.to_i-1, x.to_i-1, t]
  total += t
end

values = []
(0...height).each do |y|
  (0...width).each do |x|
    size = min_size
    dir = -1
    continue = true
    while continue
      legal = legal_triangle(y, x, size, dir, height, width)
      if legal
        values << get_value(y, x, size, dir, fishies)
        size += 1
        #puts total - values[-1]
      else
        if dir == -1
          size = min_size
          dir = 1
        else
          continue = false
        end
      end
    end
  end
end

puts(total - values.min)

*/