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<bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<vector<pair<int, int>>> rgw(n, vector<pair<int, int>>(m, pair<int, int>()));
vector<vector<char>> grid(n, vector<char>(m));
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
}
}
for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j++) {
if (grid[i][j] == 'R' && i + 2 < n && grid[i + 1][j] == 'G' && grid[i + 2][j] == 'W') {
rgw[i + 1][j].first = 1;
}
if (grid[i][j] == 'R' && j + 2 < m && grid[i][j + 1] == 'G' && grid[i][j + 2] == 'W') {
rgw[i][j + 1].second = 1;
}
}
}
/*for (int i = 0; i < n; i ++) {
for (int j = 0; j < m; j++) {
cout << rgw[i][j].first << " " << rgw[i][j].second << endl;
}
}*/
long long prze, wyn = 0, akwyn;
for (int i = 1; i < n + m - 1; i++) {
akwyn = 0;
prze = 0;
for (int j = i; j >= 0; j--) {
if (i - j < n && j < m) {
if (rgw[i - j][j].first == 1 && rgw[i - j][j].second == 0) {
akwyn += 1 + prze;
prze = 0;
if (i - j + 1 < n && j - 1 < m) {
rgw[i - j + 1][j - 1].second = 0;
}
}
else if (rgw[i - j][j].first == 0 && rgw[i - j][j].second == 1) {
akwyn += 1 + prze;
prze = 0;
if (i - j + 1 < n && j - 1 < m) {
rgw[i - j + 1][j - 1].first = 0;
}
}
else if (rgw[i - j][j].first == 1 && rgw[i - j][j].second == 1) {
prze += 1;
}
else {
akwyn += prze;
prze = 0;
}
}
}
akwyn += prze;
wyn += akwyn;
}
cout << wyn;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |