-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathFilled Subgrid Count I.cpp
More file actions
51 lines (45 loc) · 1.19 KB
/
Copy pathFilled Subgrid Count I.cpp
File metadata and controls
51 lines (45 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;
const int N = 3005;
string grid[N];
long long dp_up[N][N];
long long dp_left[N][N];
long long dp_square[N][N];
long long res[26];
void solve() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> grid[i];
}
for (int l = 0; l < k; l++) {
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (grid[i-1][j-1] != 'A' + l) {
dp_up[i][j] = 0;
dp_left[i][j] = 0;
dp_square[i][j] = 0;
// cout << 0 << " ";
continue;
}
dp_up[i][j] = dp_up[i-1][j]+1;
dp_left[i][j] = dp_left[i][j-1]+1;
dp_square[i][j] = min({
dp_up[i-1][j],
dp_left[i][j-1],
dp_square[i-1][j-1]
}) + 1;
res[l] += dp_square[i][j];
// cout << dp_left[i][j] << " ";
}
// cout << endl;
}
}
for (int i = 0; i < k; i++) {
cout << res[i] << " ";
}
cout << endl;
}
int main() {
solve();
}