Submission #1140309

#TimeUsernameProblemLanguageResultExecution timeMemory
1140309goatmarCatfish Farm (IOI22_fish)C++20
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <unordered_map> #include <algorithm> using namespace std; // Estructura para representar un bagre struct Bagre { int x, y, peso; }; // Función para calcular el peso máximo de bagres que se pueden capturar int64_t max_weights(int N, int M, const vector<int>& X, const vector<int>& Y, const vector<int>& W) { // Mapa para almacenar los bagres por columna unordered_map<int, vector<Bagre>> bagresPorColumna; // Llenar el mapa con los bagres for (int i = 0; i < M; ++i) { bagresPorColumna[X[i]].push_back({X[i], Y[i], W[i]}); } int64_t pesoTotal = 0; // Iterar sobre cada columna for (int c = 0; c < N; ++c) { // Si no hay bagres en esta columna, continuar if (bagresPorColumna.find(c) == bagresPorColumna.end()) continue; // Ordenar los bagres en esta columna por su posición en Y auto& bagres = bagresPorColumna[c]; sort(bagres.begin(), bagres.end(), [](const Bagre& a, const Bagre& b) { return a.y < b.y; }); // Determinar la longitud máxima del muelle en esta columna int longitudMuelle = bagres.back().y; // Verificar si los bagres en las columnas adyacentes pueden ser capturados for (const auto& bagre : bagres) { if (bagre.y > longitudMuelle) continue; bool puedeSerCapturado = false; // Verificar columna a la izquierda if (c > 0 && bagresPorColumna.find(c - 1) != bagresPorColumna.end()) { for (const auto& bagreIzq : bagresPorColumna[c - 1]) { if (bagreIzq.y == bagre.y && bagreIzq.y <= longitudMuelle) { puedeSerCapturado = true; break; } } } // Verificar columna a la derecha if (c < N - 1 && bagresPorColumna.find(c + 1) != bagresPorColumna.end()) { for (const auto& bagreDer : bagresPorColumna[c + 1]) { if (bagreDer.y == bagre.y && bagreDer.y <= longitudMuelle) { puedeSerCapturado = true; break; } } } // Si el bagre puede ser capturado, sumar su peso al total if (puedeSerCapturado) { pesoTotal += bagre.peso; } } } return pesoTotal; } int main() { int N = 5; int M = 4; vector<int> X = {0, 1, 4, 3}; vector<int> Y = {2, 1, 4, 3}; vector<int> W = {5, 2, 1, 3}; int64_t resultado = max_weights(N, M, X, Y, W); cout << "Peso máximo de bagres que se pueden capturar: " << resultado << " gramos" << endl; return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccx4hZtl.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cchrW1oO.o:fish.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccx4hZtl.o: in function `main':
grader.cpp:(.text.startup+0x267): undefined reference to `max_weights(int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status