#include <iostream>
#include <fstream>
using namespace std;
const int nmax=3005;
int dp[nmax][nmax][2];
string s[nmax];
int n,m,i,j,ans;
int main()
{
ios_base::sync_with_stdio(false);
//freopen("data.in","r",stdin);
cin>>n>>m;
for(i=1;i<=n;i++)
{
cin>>s[i];
s[i]=" "+s[i]+" ";
}
for(i=1;i<=m+1;i++)
s[0]+=" ",s[n+1]+=" ";
for(i=1;i<=n;i++)
for(j=m;j>=1;j--)
{
dp[i][j][0]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]);
dp[i][j][1]=max(dp[i-1][j+1][0],dp[i-1][j+1][1]);
if(s[i][j]=='G')
{
if(s[i-1][j]=='R'&&s[i+1][j]=='W') dp[i][j][0]=max(dp[i-1][j+1][1]+1,dp[i][j][0]);
if(s[i][j-1]=='R'&&s[i][j+1]=='W') dp[i][j][1]=max(dp[i-1][j+1][0]+1,dp[i][j][1]);
}
if(j==1||i==n) ans+=max(dp[i][j][0],dp[i][j][1]);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
512 KB |
Output is correct |
4 |
Correct |
3 ms |
512 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Incorrect |
3 ms |
512 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |