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;
#define int long long
#define pii pair<long long, long long>
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<vector<char>> a(n, vector<char>(m));
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
}
}
int ans = 0;
for (int d = 0; d < n + m - 1; d++) {
int x, y;
if (d < n) x = d, y = 0;
else x = n - 1, y = d - n + 1;
vector<int> dpx(2), dpy(2);
int s;
while (x >= 0 && y < m) {
dpx.push_back(0);
dpy.push_back(0);
s = dpx.size();
if (x > 0 && x < n - 1 && a[x][y] == 'G' && a[x - 1][y] == 'R' && a[x + 1][y] == 'W') {
dpx[s - 1] = max(dpx[s - 2], dpy[s - 3]) + 1;
}
if (y > 0 && y < m - 1 && a[x][y] == 'G' && a[x][y - 1] == 'R' && a[x][y + 1] == 'W') {
dpy[s - 1] = max(dpy[s - 2], dpx[s - 3]) + 1;
}
x--, y++;
}
/*for (int i = 0; i < s; i++) cout << dpx[i] << " ";
cout << "\n";
for (int i = 0; i < s; i++) cout << dpy[i] << " ";
cout << "\n";*/
int mx = 0;
for (int i = 0; i < s; i++) mx = max({mx, dpx[i], dpy[i]});
ans += mx;
}
cout << ans << "\n";
}
Compilation message (stderr)
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:51:27: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
51 | for (int i = 0; i < s; i++) mx = max({mx, dpx[i], dpy[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... |