#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
const int N=3005;
char a[N][N];
bool vis[N][N];
int cnt=0;
int dp[N][N];
signed main(){
int n,m;
cin>>n>>m;
for(int i=1+3;i<=n+3;i++){
for(int j=1+3;j<=m+3;j++){
cin>>a[i][j];
}
}
for(int i=1+3;i<=n+3;i++){
for(int j=1+3;j<=m+3;j++){
dp[i][j]=max(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1],dp[i][j]);
if(a[i][j]=='W' and a[i][j-1]=='G' and a[i][j-2]=='R'){
dp[i][j]=max(dp[i][j],dp[i-1][j]+dp[i][j-3]-dp[i-1][j-3]+1);
}
if(a[i][j]=='W' and a[i-1][j]=='G' and a[i-2][j]=='R'){
dp[i][j]=max(dp[i][j],dp[i][j-1]+dp[i-3][j]-dp[i-3][j-1]+1);
}
}
}
cout<<dp[n+3][m+3];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |