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;
const int MXN = 3005;
int n, m;
int grid[MXN][MXN];
int can[MXN][MXN];
int dp[MXN][3];
signed main() {
cin >> n >> m;
for (int i=1; i<=n; i++) {
string s;
cin >> s;
for (int j=1; j<=m; j++) {
if (s[j-1] == 'R') grid[i][j] = 1;
if (s[j-1] == 'G') grid[i][j] = 2;
if (s[j-1] == 'W') grid[i][j] = 3;
}
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
if (grid[i][j] == 2) {
if (grid[i-1][j] == 1 && grid[i+1][j] == 3) {
can[i][j] += 1;
}
if (grid[i][j-1] == 1 && grid[i][j+1] == 3) {
can[i][j] += 2;
}
}
}
}
int ans = 0;
for (int diag=2; diag<=n+m; diag++) {
dp[0][0] = dp[0][1] = dp[0][2] = 0;
int here = 0;
vector<int> vc;
vc.push_back(-1);
for (int i=1; i<=n; i++) {
int j = diag - i;
if (j >= 1 && j <= m) {
vc.push_back(can[i][j]);
}
}
for (int i=1; i<vc.size(); i++) {
dp[i][0] = dp[i][1] = dp[i][2] = 0;
dp[i][0] = max(max(dp[i-1][0], dp[i-1][1]), dp[i-1][2]);
if (vc[i] & 1) {
dp[i][1] = max(dp[i][1], 1 + max(dp[i-1][0], dp[i-1][1]));
}
if (vc[i] & 2) {
dp[i][2] = max(dp[i][2], 1 + max(dp[i-1][0], dp[i-1][2]));
}
here = max(here, max(max(dp[i][0], dp[i][1]), dp[i][2]));
}
ans += here;
}
cout << ans << endl;
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i=1; i<vc.size(); i++) {
| ~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |