#include <bits/stdc++.h>
using namespace std;
#define sp << " " <<
#define int long long
#define vi vector<int>
#define F(xxx,yyy) for (int xxx=1;xxx<=yyy;xxx++)
#define pii pair<int,int>
const int N = 2e5+1;
const int MOD = 1e9+7;
void solve() {
int n,m;
cin >> n >> m;
char a[n+1][m+1];
bool ctd[n+1][m+1];
memset(ctd,0,sizeof ctd);
F(i,n) {
string s;
cin >> s;
F(j,m) a[i][j] = s[j-1];
}
vi ans(6,0);
F(i,n) {
F(j,m) {
if (a[i][j] == '.') continue;
if (ctd[i][j]) continue;
if (i<n-1 && j<m) {
if (a[i][j] == a[i+1][j] && a[i+1][j]==a[i+1][j+1] && a[i+1][j+1]==a[i+2][j+1]) {
ctd[i][j] = ctd[i+1][j] = ctd[i+1][j+1] = ctd[i+2][j+1] = 1;
ans[3]++;
continue;
}
}
if (i<n && j>1 && j<m) {
if (a[i][j] == a[i][j+1] && a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j-1]) {
ctd[i][j] = ctd[i][j+1] = ctd[i+1][j] = ctd[i+1][j-1] = 1;
ans[3]++;
continue;
}
}
if (i<n-1 && j>1) {
if (a[i][j] == a[i+1][j] && a[i+1][j]==a[i+1][j-1] && a[i+1][j-1]==a[i+2][j-1]) {
ctd[i][j] = ctd[i+1][j] = ctd[i+1][j-1] = ctd[i+2][j-1] = 1;
ans[4]++;
continue;
}
}
if (i<n && j<m-1) {
if (a[i][j] == a[i][j+1] && a[i][j+1] == a[i+1][j+1] && a[i+1][j+1] == a[i+1][j+2]) {
ctd[i][j] = ctd[i][j+1] = ctd[i+1][j+1] = ctd[i+1][j+2] = 1;
ans[4]++;
continue;
}
}
}
}
vi dx = {0,1,0,-1};
vi dy = {1,0,-1,0};
int adj[n+5][m+5];
memset(adj,0,sizeof adj);
F(i,n) {
F(j,m) {
for (int k=0;k<4;k++) {
int gx = i+dx[k];
int gy = j+dy[k];
if (gx >= 1 && gx <= n && gy >= 1 && gy <= m && a[gx][gy]>='a' && a[gx][gy]<='z' && a[gx][gy] == a[i][j]) {
adj[i][j]++;
}
}
}
}
F(i,n) {
F(j,m) {
if (ctd[i][j]) continue;
if (adj[i][j] == 3) {
ans[5]++;
ctd[i][j] = ctd[i][j+1] = ctd[i][j-1] = ctd[i-1][j] = 1;
}
}
}
F(i,n) {
F(j,m) {
if (ctd[i][j]) continue;
if (j<m-2 && adj[i][j] == 1 && adj[i][j+1] == 2 && adj[i][j+2] == 2 && adj[i][j+3] == 1 && a[i][j] == a[i][j+1] && a[i][j+1] ==a[i][j+2] && a[i][j+3] == a[i][j+2]) {
ans[2]++;
ctd[i][j] = ctd[i][j+1] = ctd[i][j+2] = ctd[i][j+3] = 1;
}
}
}
F(i,n) {
F(j,m) {
if (ctd[i][j]) continue;
if (i<n-2 && adj[i][j] == 1 && adj[i+1][j] == 2 && adj[i+2][j] == 2 && adj[i+3][j] == 1 && a[i][j] == a[i+1][j] && a[i+1][j] == a[i+2][j] && a[i+2][j] == a[i+3][j]) {
ans[2]++;
ctd[i][j] = ctd[i+1][j] = ctd[i+2][j] = ctd[i+3][j] = 1;
}
}
}
F(i,n){
F(j,m) {
if (a[i][j] == '.') continue;
if (ctd[i][j]) continue;
if (i<n && j<m && a[i][j] == a[i+1][j] && a[i+1][j] == a[i][j+1] && a[i][j+1] == a[i+1][j+1]) {
ans[1]++;
}
}
}
F(i,5) cout << ans[i] << "\n";
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Local
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int t = 1;
//cin >> t;
F(i,t) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |