diff options
Diffstat (limited to '16_counting_problems')
| -rwxr-xr-x | 16_counting_problems/a.out | bin | 0 -> 14160 bytes | |||
| -rw-r--r-- | 16_counting_problems/filled_subgrid_count_i_3413.cpp | 38 |
2 files changed, 38 insertions, 0 deletions
diff --git a/16_counting_problems/a.out b/16_counting_problems/a.out new file mode 100755 index 0000000..fc90929 --- /dev/null +++ b/16_counting_problems/a.out | |||
| Binary files differ | |||
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 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <iostream> | ||
| 3 | #include <string> | ||
| 4 | #include <vector> | ||
| 5 | |||
| 6 | void fill(const std::vector<std::vector<char>>& a, | ||
| 7 | std::vector<std::vector<long long>>& t, int i, int j) { | ||
| 8 | if (a[i][j]==a[i][j+1] && a[i][j]==a[i+1][j] && a[i][j]==a[i+1][j+1]) | ||
| 9 | t[i][j] = 1+std::min({t[i+1][j], t[i][j+1], t[i+1][j+1]}); | ||
| 10 | } | ||
| 11 | |||
| 12 | int main() { | ||
| 13 | int n, k; | ||
| 14 | std::string s; | ||
| 15 | std::cin >> n >> k; | ||
| 16 | std::vector<std::vector<char>> a(n, std::vector<char>(n)); | ||
| 17 | std::vector<std::vector<long long>> t(n, std::vector<long long>(n, 1)); | ||
| 18 | for (int i = 0; i < n; i++) { | ||
| 19 | std::cin >> s; | ||
| 20 | for (int j = 0; j < n; j++) | ||
| 21 | a[i][j] = s[j]; | ||
| 22 | } | ||
| 23 | |||
| 24 | for (int d = n-2; d >= 0; d--) { | ||
| 25 | for (int i = d; i >= 0; i--) { | ||
| 26 | fill(a, t, i, d); | ||
| 27 | fill(a, t, d, i); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | std::vector<long long> sol(k, 0); | ||
| 32 | for (int i = 0; i < n; i++) | ||
| 33 | for (int j = 0; j < n; j++) | ||
| 34 | sol[a[i][j]-'A'] += t[i][j]; | ||
| 35 | |||
| 36 | for (auto x : sol) | ||
| 37 | std::cout << x << "\n"; | ||
| 38 | } | ||
