//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-O2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 3000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000010;
const ll LOG = 25;
int n, m, mark[N][N], cnt;
char a[N][N];
vector<pii> G[N][N];
void DFS(pii v){
cnt++;
mark[v.F][v.S] = 1;
for (auto u:G[v.F][v.S]){
if (mark[u.F][u.S] == 0) DFS(u);
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
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 - 2; j++){
if (a[i][j] == 'R' && a[i][j + 1] == 'G' && a[i][j + 2] == 'W') G[i][j].pb({i, j + 2}), G[i][j + 2].pb({i, j});
}
for (int i = 1; i <= n - 2; i++){
for (int j = 1; j <= m; j++){
if (a[i][j] == 'R' && a[i + 1][j] == 'G' && a[i + 2][j] == 'W') G[i][j].pb({i + 2, j}), G[i + 2][j].pb({i, j});
}
}
int ans = 0;
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++){
if (mark[i][j] == 0){
cnt = 0;
DFS({i, j});
ans += cnt / 2;
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
213116 KB |
Output is correct |
2 |
Correct |
119 ms |
213112 KB |
Output is correct |
3 |
Correct |
115 ms |
213188 KB |
Output is correct |
4 |
Correct |
115 ms |
213240 KB |
Output is correct |
5 |
Correct |
116 ms |
213112 KB |
Output is correct |
6 |
Correct |
120 ms |
213112 KB |
Output is correct |
7 |
Correct |
115 ms |
213216 KB |
Output is correct |
8 |
Correct |
117 ms |
213112 KB |
Output is correct |
9 |
Correct |
118 ms |
213116 KB |
Output is correct |
10 |
Correct |
114 ms |
213112 KB |
Output is correct |
11 |
Correct |
124 ms |
213072 KB |
Output is correct |
12 |
Correct |
120 ms |
213112 KB |
Output is correct |
13 |
Correct |
118 ms |
213240 KB |
Output is correct |
14 |
Correct |
113 ms |
213112 KB |
Output is correct |
15 |
Correct |
116 ms |
213112 KB |
Output is correct |
16 |
Correct |
118 ms |
213112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
213116 KB |
Output is correct |
2 |
Correct |
119 ms |
213112 KB |
Output is correct |
3 |
Correct |
115 ms |
213188 KB |
Output is correct |
4 |
Correct |
115 ms |
213240 KB |
Output is correct |
5 |
Correct |
116 ms |
213112 KB |
Output is correct |
6 |
Correct |
120 ms |
213112 KB |
Output is correct |
7 |
Correct |
115 ms |
213216 KB |
Output is correct |
8 |
Correct |
117 ms |
213112 KB |
Output is correct |
9 |
Correct |
118 ms |
213116 KB |
Output is correct |
10 |
Correct |
114 ms |
213112 KB |
Output is correct |
11 |
Correct |
124 ms |
213072 KB |
Output is correct |
12 |
Correct |
120 ms |
213112 KB |
Output is correct |
13 |
Correct |
118 ms |
213240 KB |
Output is correct |
14 |
Correct |
113 ms |
213112 KB |
Output is correct |
15 |
Correct |
116 ms |
213112 KB |
Output is correct |
16 |
Correct |
118 ms |
213112 KB |
Output is correct |
17 |
Incorrect |
120 ms |
213128 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
213116 KB |
Output is correct |
2 |
Correct |
119 ms |
213112 KB |
Output is correct |
3 |
Correct |
115 ms |
213188 KB |
Output is correct |
4 |
Correct |
115 ms |
213240 KB |
Output is correct |
5 |
Correct |
116 ms |
213112 KB |
Output is correct |
6 |
Correct |
120 ms |
213112 KB |
Output is correct |
7 |
Correct |
115 ms |
213216 KB |
Output is correct |
8 |
Correct |
117 ms |
213112 KB |
Output is correct |
9 |
Correct |
118 ms |
213116 KB |
Output is correct |
10 |
Correct |
114 ms |
213112 KB |
Output is correct |
11 |
Correct |
124 ms |
213072 KB |
Output is correct |
12 |
Correct |
120 ms |
213112 KB |
Output is correct |
13 |
Correct |
118 ms |
213240 KB |
Output is correct |
14 |
Correct |
113 ms |
213112 KB |
Output is correct |
15 |
Correct |
116 ms |
213112 KB |
Output is correct |
16 |
Correct |
118 ms |
213112 KB |
Output is correct |
17 |
Incorrect |
120 ms |
213128 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |