CSES - Datatähti 2024 alku - Results
Submission details
Task:Uolevin kalansaalis
Sender:rottis
Submission time:2023-11-12 22:17:29 +0200
Language: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:22: error: no matching function for call to 'begin(std::vector<int>*&)'
   83 |   for (int fish[3] : fishies) {
      |                      ^~~~~~~
In file included from /usr/include/c++/11/bits/algorithmfwd.h:39,
                 from /usr/include/c++/11/bits/stl_algo.h:60,
                 from /usr/include/c++/11/string:52,
                 from /usr/include/c++/11/bits/locale_classes.h:40,
                 from /usr/include/c++/11/bits/ios_base.h:41,
                 from /usr/include/c++/11/ios:42,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from input/code.cpp:8:
/usr/include/c++/11/initializer_list:90:5: note: candidate: 'template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)'
   90 |     begin(initializer_list<_Tp> __ils) noexcept
      |     ^~~~~
/usr/include/c++/11/ini...

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

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)

*/