#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define printLn(n) cout << n << '\n'
using namespace std;
typedef long long ll;
const ll HORIZONTAL = 0;
const ll VERTICAL = 1;
const ll EMPTY = 2;
ll readLL();
string readStr();
void resolve();
bool check(const vector<string> &field, ll i, ll j, ll dir);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
resolve();
return 0;
}
void resolve() {
ll height = readLL();
ll width = readLL();
vector<string> field(height);
for (int i = 0; i < height; ++i) {
field[i] = readStr();
}
vector<vector<vector<ll>>> dp(height, vector<vector<ll>>(width, vector<ll>(2, 0)));
ll res = 0;
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
ll prevHor = 0;
ll prevEmp = 0;
ll prevVer = 0;
if (i > 0 && j > 0) {
prevHor = dp[i - 1][j - 1][HORIZONTAL];
prevVer = dp[i - 1][j - 1][VERTICAL];
prevEmp = dp[i - 1][j - 1][EMPTY];
}
dp[i][j][EMPTY] = max(prevEmp, max(prevHor, prevVer));
if (check(field, i, j, VERTICAL)) {
dp[i][j][VERTICAL] = 1 + max(prevVer, prevEmp);
}
if (check(field, i, j, HORIZONTAL)) {
dp[i][j][HORIZONTAL] = 1 + max(prevHor, prevEmp);
}
if (i == height - 1 || j == width - 1) {
res += max(dp[i][j][EMPTY], max(dp[i][j][HORIZONTAL], dp[i][j][VERTICAL]));
}
}
}
printLn(res);
}
bool check(const vector<string> &field, ll i, ll j, ll dir) {
if (dir == HORIZONTAL) {
return (field[i][j - 1] == 'R' && field[i][j] == 'G' && field[i][j + 1] == 'W');
} else if (dir == VERTICAL) {
return (field[i - 1][j] == 'R' && field[i][j] == 'G' && field[i + 1][j] == 'W');
}
return false;
}
ll readLL() {
ll num;
cin >> num;
return num;
}
string readStr() {
string num;
cin >> num;
return num;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |