#include <bits/stdc++.h>
#define endl "\n"
#define sz = s.size()
using ll = long long;
const int Z = 1e8+9;
const int INF = 1e9+9;
const int mod = 1e9+7;
using namespace std;
ll fp (ll x, ll y)
{
if (y == 0) return 1;
if (y == 1) return x;
ll ret = fp(x, y/2) % mod;
if (y % 2) ret *= x;
return ret;
}
char a[100][100];
ll valid[555][555];
ll x, n, mn, mx, sum, ans, dif, t, k , m ;
ll fig1 , fig2 , fig3 , fig4 , fig5 ;
int main()
{
ios::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m;
for (int i = 1 ; i <= n ; i++)
for (int j = 1 ; j <= m ; j++)
cin >> a[i][j];
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
if (valid[i][j] || a[i][j] == '.') continue;
if (a[i][j] == 0) break ;
if (a[i][j] == a[i][j+1] && a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j+1]){
fig1++;
valid[i][j]++;
valid[i][j+1]++;
valid[i+1][j]++;
valid[i+1][j+1]++;
}
}
}
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
if (valid[i][j] || a[i][j] == '.') continue;
if (a[i][j] == 0) break ;
if (a[i][j] == a[i][j+1] && a[i][j] == a[i][j+2] && a[i][j] == a[i][j+3]){
fig2++;
valid[i][j] = 1;
valid[i][j+1] = 1;
valid[i][j+2] = 1;
valid[i][j+3] = 1;
}
else if (a[i][j] == a[i+1][j] && a[i][j] == a[i+2][j] && a[i][j] == a[i+3][j]){
fig2++;
valid[i][j] = 1;
valid[i+1][j] = 1;
valid[i+2][j] = 1;
valid[i+3][j] = 1;
}
}
}
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
if (valid[i][j] || a[i][j] == '.') continue;
if (a[i][j] == 0) break ;
if (a[i][j] == a[i][j+1] && a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j-1]){
fig3++;
valid[i][j]++;
valid[i][j+1]++;
valid[i+1][j]++;
valid[i+1][j-1]++;
}
else if (a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j+1] && a[i][j] == a[i+2][j+1]){
fig3++;
valid[i][j]++;
valid[i][j+1]++;
valid[i+1][j]++;
valid[i+1][j-1]++;
}
}
}
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
if (valid[i][j] || a[i][j] == '.') continue;
if (a[i][j] == 0) break ;
if (a[i][j] == a[i][j+1] && a[i][j] == a[i+1][j+1] && a[i][j] == a[i+1][j+2]){
fig4++;
valid[i][j]++;
valid[i][j+1]++;
valid[i+1][j]++;
valid[i+1][j-1]++;
}
else if (a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j-1] && a[i][j] == a[i+2][j-1]){
fig4++;
valid[i][j]++;
valid[i][j+1]++;
valid[i+1][j]++;
valid[i+1][j-1]++;
}
}
}
for (int i = 1 ; i <= n ; i++){
for (int j = 1 ; j <= m ; j++){
if (valid[i][j]) continue;
if (a[i][j] == 0) break ;
if (a[i][j] == a[i+1][j] && a[i][j] == a[i+1][j-1] && a[i][j] == a[i+1][j+1]){
fig5++;
valid[i][j]++;
valid[i+1][j]++;
valid[i+1][j+1]++;
valid[i+1][j-1]++;
}
else if (a[i][j] == a[i][j-1] && a[i][j] == a[i-1][j-1] && a[i][j] == a[i+1][j-1]){
fig5++;
valid[i][j]++;
valid[i][j-1]++;
valid[i+1][j-1]++;
valid[i-1][j-1]++;
}
else if (a[i][j] == a[i][j+1] && a[i][j] == a[i+1][j+1] && a[i][j] == a[i-1][j+1]){
fig5++;
valid[i][j]++;
valid[i][j+1]++;
valid[i+1][j+1]++;
valid[i-1][j+1]++;
}
else if (a[i][j] == a[i-1][j] && a[i][j] == a[i-1][j-1] && a[i][j] == a[i-1][j+1]){
fig5++;
valid[i][j]++;
valid[i-1][j]++;
valid[i-1][j+1]++;
valid[i-1][j-1]++;
}
}
}
cout << fig1 << endl << fig2 << endl << fig3 << endl << fig4 << endl << fig5;
return 0 ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
7 |
Incorrect |
0 ms |
320 KB |
Output isn't correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Incorrect |
0 ms |
332 KB |
Output isn't correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |