이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
using namespace std;
int N, M, ans;
char a[3010][3010];
int dp[3010][3010][3];
bool ver(int x, int y) {
return a[x-1][y]=='R' && a[x][y]=='G' && a[x+1][y]=='W';
}
bool hor(int x, int y) {
return a[x][y-1]=='R' && a[x][y]=='G' && a[x][y+1]=='W';
}
int main()
{
cin >> N >> M;
for(int i=1; i<=N; i++) {
for(int j=1; j<=M; j++) {
cin >> a[i][j];
}
}
for(int i=1; i<=N; i++) {
for(int j=M; j>=1; j--) {
dp[i][j][0] = max(dp[i-1][j+1][0], max(dp[i-1][j+1][1], dp[i-1][j+1][2]));
dp[i][j][1] = (!ver(i,j) ? int(-1e9) : 1 + max(dp[i-1][j+1][0], dp[i-1][j+1][1]));
dp[i][j][2] = (!hor(i,j) ? int(-1e9) : 1 + max(dp[i-1][j+1][0], dp[i-1][j+1][2]));
}
}
for(int i=1; i<=N; i++) {
for(int j=1; j<=M; j++) {
if (i==N || j==1) {
ans += max(dp[i][j][0], max(dp[i][j][1], dp[i][j][2]));
}
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |