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

Compiler report

input/code.cpp:81:73: error: wrong number of template arguments (3, should be at least 1)
   81 | int get_value(int y, int x, int size, int dir, std::vector<int, int, int> *fishies) {
      |                                                                         ^
In file included from /usr/include/c++/11/vector:67,
                 from input/code.cpp:10:
/usr/include/c++/11/bits/stl_vector.h:389:11: note: provided for 'template<class _Tp, class _Alloc> class std::vector'
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
input/code.cpp: In function 'int get_value(int, int, int, int, int*)':
input/code.cpp:83:12: error: expected identifier before numeric constant
   83 |   for (int[3] fish : &fishies) {
      |            ^
input/code.cpp:83:12: error: expected ']' before numeric constant
   83 |   for (int[3] fish : &fishies) {
      |            ^
      |            ]
input/code.cpp:83:11: error: structured binding declaration cannot have type '...

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, int, int> *fishies) {
  int val = 0;
  for (int[3] fish : &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)

*/