This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<utility>
#define int long long
#define INF 1000000000000000000
#define pii pair<long long, long long>
using namespace std;
int n, m;
char v[3005][3005];
/*
r c
0 : - -
1 : + -
2 : - +
3 : + +
*/
int ans = 0;
int cmp(int i, int j) {
if (i < 0 || i >= n || j < 0 || j >= m || v[i][j] != 'G') return -1;
int row = 0, column = 0;
if (i > 0 && i < n-1 && v[i-1][j] == 'R' && v[i+1][j] == 'W') column++;
if (j > 0 && j < m-1 && v[i][j-1] == 'R' && v[i][j+1] == 'W') row++;
if (column && row) {
v[i][j] = '/';
ans+=2;
return 3;
}
if (row) {
v[i][j] = v[i][j-1] = v[i][j+1] = '/';
ans++;
return 1;
}
if (column) {
v[i][j] = v[i-1][j] = v[i+1][j] = '/';
ans++;
return 2;
}
return 0;
}
signed main() {
cin >> n >> m;
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) cin >> v[i][j];
}
for (int i = 0 ; i < n ; i++) {
for (int j = 0 ; j < m ; j++) {
//cout << cmp(i, j) <<" ";
int ti = i, tj = j;
while (cmp(ti, tj) == 3) {
//v[ti][tj] = '/';
ti++, tj--;
}
//v[ti][tj] = '/';
}
cout << "\n";
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |