#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
const int inf = 0x3f3f3f3f;
const ll linf = 123456789012345678;
const ll mod = 998244353;
#pragma GCC optimize("Ofast")
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " = " << x << endl
int n, m;
vvi a;
vi par;
vi siz;
int find(int a){
if(par[a] == -1) return a;
return (par[a] = find(par[a]));
}
void join(int a, int b){
a = find(a);
b = find(b);
if(a == b) return;
par[a] = b;
siz[b] += siz[a];
siz[a] = 0;
}
int main(){
cin >> n >> m;
a = vvi(n, vi(m));
for(int i = 0; i < n; i++){
string s;
cin >> s;
for(int j = 0; j < m; j++){
if(s[j] == 'G') a[i][j] = 1;
else if(s[j] == 'W') a[i][j] = 2;
}
}
par = vi(n*m*2, -1);
siz = vi(n*m*2, 0);
int ans = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
if(a[i][j] == 0){
if(i+2<n && a[i+1][j] == 1 && a[i+2][j] == 2) {
if(j-1 >= 0) join(i*m+j+n*m, (i+1)*m+j-1);
if(j-2 >= 0) join(i*m+j+n*m, (i+2)*m+j-2);
ans++;
siz[find(i*m+j)]++;
}
if(j+2<m && a[i][j+1] == 1 && a[i][j+2] == 2){
if(i-1 >= 0) join(i*m+j, (i-1)*m+j+1+n*m);
if(i-2 >= 0) join(i*m+j, (i-2)*m+j+2+n*m);
ans++;
siz[find(i*m+j)]++;
}
}
}
}
int extra = 0;
for(int i = 0; i < n*m*2; i++){
extra+=(siz[i]&1);
}
cout << ans/2+(extra+1)/2 << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |