#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#define printLn(n) cout << n << '\n'
using namespace std;
short item = 0;
vector<vector<char>> field(3000 + 2, vector<char>(3000 + 2, '#'));
vector<vector<vector<short>>> dp(3000 + 2, vector<vector<short>>(3000 + 2, vector<short>(3, item)));
const short EMPTY = 0;
const short HORIZONTAL = 1;
const short VERTICAL = 2;
short readLL();
string readStr();
void resolve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
resolve();
return 0;
}
void resolve() {
short height = readLL();
short width = readLL();
for (short i = 1; i <= height; ++i) {
string str = readStr();
for (short j = 1; j <= width; ++j) {
field[i][j] = str[j - 1];
}
}
int res = 0;
for (short i = 1; i <= height; ++i) {
for (short j = 1; j <= width; ++j) {
dp[i][j][EMPTY] = max(dp[i - 1][j + 1][EMPTY], max(dp[i - 1][j + 1][HORIZONTAL], dp[i - 1][j + 1][VERTICAL]));
if (field[i - 1][j] == 'R' && field[i][j] == 'G' && field[i + 1][j] == 'W') {
dp[i][j][VERTICAL] = 1 + max(dp[i - 1][j + 1][VERTICAL], dp[i - 1][j + 1][EMPTY]);
}
if (field[i][j - 1] == 'R' && field[i][j] == 'G' && field[i][j + 1] == 'W') {
dp[i][j][HORIZONTAL] = 1 + max(dp[i - 1][j + 1][HORIZONTAL], dp[i - 1][j + 1][EMPTY]);
}
if (i == height || j == 1) {
res += max(dp[i][j][EMPTY], max(dp[i][j][HORIZONTAL], dp[i][j][VERTICAL]));
}
}
}
printLn(res);
}
short readLL() {
short num;
cin >> num;
return num;
}
string readStr() {
string num;
cin >> num;
return num;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
185 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
185 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
185 ms |
262148 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |