From 96254947699986c59f0dc63d69fd4b76bd3ed43e Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Mon, 6 Jul 2026 19:08:08 +0200 Subject: Initial commit --- .../filled_subgrid_count_i_3413.cpp | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 16_counting_problems/filled_subgrid_count_i_3413.cpp (limited to '16_counting_problems/filled_subgrid_count_i_3413.cpp') diff --git a/16_counting_problems/filled_subgrid_count_i_3413.cpp b/16_counting_problems/filled_subgrid_count_i_3413.cpp new file mode 100644 index 0000000..77f7de1 --- /dev/null +++ b/16_counting_problems/filled_subgrid_count_i_3413.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +void fill(const std::vector>& a, + std::vector>& t, int i, int j) { + if (a[i][j]==a[i][j+1] && a[i][j]==a[i+1][j] && a[i][j]==a[i+1][j+1]) + t[i][j] = 1+std::min({t[i+1][j], t[i][j+1], t[i+1][j+1]}); +} + +int main() { + int n, k; + std::string s; + std::cin >> n >> k; + std::vector> a(n, std::vector(n)); + std::vector> t(n, std::vector(n, 1)); + for (int i = 0; i < n; i++) { + std::cin >> s; + for (int j = 0; j < n; j++) + a[i][j] = s[j]; + } + + for (int d = n-2; d >= 0; d--) { + for (int i = d; i >= 0; i--) { + fill(a, t, i, d); + fill(a, t, d, i); + } + } + + std::vector sol(k, 0); + for (int i = 0; i < n; i++) + for (int j = 0; j < n; j++) + sol[a[i][j]-'A'] += t[i][j]; + + for (auto x : sol) + std::cout << x << "\n"; +} -- cgit v1.3