이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 3e3 + 2;
const int inf = 2e9;
int mat[N][N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> c(n + m - 1);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
char ch; cin >> ch;
if (ch == 'R') mat[i][j] = 0;
if (ch == 'G') mat[i][j] = 1;
if (ch == 'W') mat[i][j] = 2;
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int val = 0;
if (j < m - 2 && mat[i][j] == 0 && mat[i][j + 1] == 1 && mat[i][j + 2] == 2) val++;
if (i < n - 2 && mat[i][j] == 0 && mat[i + 1][j] == 1 && mat[i + 2][j] == 2) val += 2;
c[i + j].push_back(val);
}
}
int ans = 0;
for (auto v : c) {
int sz = v.size();
vector<vector<int>> dp(sz + 1, vector<int>(4, -inf));
dp[0][3] = 0;
for (int i = 0; i < sz; i++) {
for (int j = 0; j < 3; j++) smax(dp[i + 1][j + 1], dp[i][j]);
smax(dp[i + 1][3], dp[i][3]);
if (v[i] % 2 == 1) {
dp[i + 1][3] = max(dp[i][2], dp[i][3]) + 1;
}
if (v[i] / 2 == 1) {
dp[i + 1][0] = *max_element(dp[i].begin(), dp[i].end()) + 1;
}
}
ans += *max_element(dp[sz].begin(), dp[sz].end());
}
cout << ans << en;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |