이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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), dp(2);
int s = 2;
while (x >= 0 && y < m) {
dpx.push_back(0);
dpy.push_back(0);
dp.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], dp[s - 2]) + 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], dp[s - 2]) + 1;
}
dp[s - 1] = max({dp[s - 2], dpx[s - 2], dpy[s - 2]});
x--, y++;
}
ans += max({dp[s - 1], dpx[s - 1], dpy[s - 1]});
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |