This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
int main(){
int n, m;
cin>>n>>m;
vector<string> vect(n);
for (int i=0;i<n;i++) cin>>vect[i];
vector<vector<int>> dp(n);
vector<vector<bool>> used(n);
for (int i=0;i<n;i++){
dp[i].resize(m);
used[i].resize(m);
}
for (int i=0;i<n;i++){
for (int j=0;j<m;j++){
if (i>0) dp[i][j]+=dp[i-1][j];
if (j>0) dp[i][j]+=dp[i][j-1];
if (i>0&&j>0) dp[i][j]-=dp[i-1][j-1];
if (i>=2&&j>=2){
if ((((vect[i][j]=='W'&&vect[i-1][j]=='G'&&vect[i-2][j]=='R')||(vect[i][j]=='R'&&vect[i-1][j]=='G'&&vect[i-2][j]=='W'))&&!used[i-1][j]&&!used[i-2][j])&&(((vect[i][j]=='W'&&vect[i][j-1]=='G'&&vect[i][j-2]=='R')||(vect[i][j]=='R'&&vect[i][j-1]=='G'&&vect[i][j-2]=='W'))&&!used[i][j-1]&&!used[i][j-2])){
if (dp[i-1][j]>dp[i][j-1]){
used[i][j]=true;
used[i][j-1]=true;
used[i][j-2]=true;
}
else{
used[i][j]=true;
used[i-1][j]=true;
used[i-2][j]=true;
}
dp[i][j]++;
continue;
}
}
if (i>=2){
if (((vect[i][j]=='W'&&vect[i-1][j]=='G'&&vect[i-2][j]=='R')||(vect[i][j]=='R'&&vect[i-1][j]=='G'&&vect[i-2][j]=='W'))&&!used[i-1][j]&&!used[i-2][j]){
used[i][j]=true;
used[i-1][j]=true;
used[i-2][j]=true;
dp[i][j]++;
continue;
}
}
if (j>=2){
if (((vect[i][j]=='W'&&vect[i][j-1]=='G'&&vect[i][j-2]=='R')||(vect[i][j]=='R'&&vect[i][j-1]=='G'&&vect[i][j-2]=='W'))&&!used[i][j-1]&&!used[i][j-2]){
used[i][j]=true;
used[i][j-1]=true;
used[i][j-2]=true;
dp[i][j]++;
continue;
}
}
}
}
cout<<dp[n-1][m-1]<<'\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... |