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 N, M;
vector<vector<char>> board;
int f(const int& i, const int& j, const int& k)
{
if (k == 1)
return board[i - 1][j] == 'R' && board[i][j] == 'G' && board[i + 1][j] == 'W';
if (k == 2)
return board[i][j - 1] == 'R' && board[i][j] == 'G' && board[i][j + 1] == 'W';
return false;
}
int main()
{
// freopen("inp.txt", "r", stdin);
ios::sync_with_stdio(false);
cin >> N >> M;
board.resize(N + 2, vector<char>(M + 2));
for (int i = 1; i <= N; i++)
for (int j = 1; j <= M; j++)
cin >> board[i][j];
int result = 0;
for (int d = 2; d <= N + M; d++)
{
vector<vector<int>> dp(M + 1, vector<int>(3));
int temp = 0;
for (int j = 1; j <= M; j++)
{
int i = d - j;
if (i < 1 || N < i) continue;
dp[j][0] = max({dp[j - 1][0], dp[j - 1][1], dp[j - 1][2]});
dp[j][1] = max(dp[j - 1][0], dp[j - 1][2]) + f(i, j, 1);
dp[j][2] = max(dp[j - 1][0], dp[j - 1][1]) + f(i, j, 2);
temp = max({dp[j][0], dp[j][1], dp[j][2]});
}
result += temp;
}
cout << result;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |