이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 3005;
typedef pair<int,int> ii;
vector<int> g[N * N];
char a[N][N];
int t[N][N];
int p[N * N];
int s[N * N];
int lead(int x) {
return p[x] == x ? x : p[x] = lead(p[x]);
}
int join(int x,int y) {
x = lead(x);
y = lead(y);
if (x == y)
return 0;
if (s[x] < s[y])
swap(x,y);
p[y] = x;
s[x] += s[y];
return 1;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int m; cin >> m;
int cnt = 0;
for(int i = 0 ; i < n ; ++i)
for(int j = 0 ; j < m ; ++j) {
cin >> a[i][j];
if (a[i][j] != 'G')
t[i][j] = cnt++;
}
iota(p,p + cnt,0);
fill(s,s + cnt,1);
for(int i = 0 ; i < n ; ++i)
for(int j = 0 ; j < m ; ++j) if (a[i][j] == 'R') {
if (a[i + 1][j] == 'G' && a[i + 2][j] == 'W')
join(t[i][j],t[i + 2][j]);
if (a[i][j + 1] == 'G' && a[i][j + 2] == 'W')
join(t[i][j],t[i][j + 2]);
}
int ans = 0;
for(int i = 0 ; i < cnt ; ++i) if (p[i] == i)
ans += s[i] / 2;
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |