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<bits/stdc++.h>
using namespace std;
int dp[3001][3001][3];
string table[3001];
int main(){
int m , n ; cin >> m >> n ;
for(int i = 1 ; i <= m ; i ++ ){
cin >> table[i] ;
table[i] = ' ' + table[i] ;
}
for(int i = 1 ; i <= m ; i ++ ){
for(int j = 1 ; j <= n ; j ++ ){
if(table[i][j] == 'G'){
if(j > 1 && j < n){
if(table[i][j - 1] == 'R' && table[i][j + 1] == 'W'){
dp[i][j][1] = max(dp[i - 1][j + 1][1] , dp[i - 1][j + 1][0]) + 1 ;
}
}
if(i > 1 && i < m){
if(table[i - 1][j] == 'R' && table[i + 1][j] == 'W'){
dp[i][j][2] = max(dp[i - 1][j + 1][2] , dp[i - 1][j + 1][0]) + 1 ;
}
}
}
dp[i][j][0] = max({dp[i - 1][j + 1][0] , dp[i - 1][j + 1][1] , dp[i - 1][j + 1][2]}) ;
}
}
int res = 0 ;
for(int i = 1 ; i <= m ; i ++ ){
res += max({dp[i][1][0] , dp[i][1][1] , dp[i][1][2]});
}
for(int j = 1 ; j <= n ; j ++ ){
res += max({dp[m][j][0] , dp[m][j][1] , dp[m][j][2]}) ;
}
res -= max({dp[n][1][0] , dp[n][1][1] , dp[n][1][2]});
cout << res ;
// for(int i = 1 ; i <= m ; i ++ ){
// for(int j = 1 ; j <= n ; j ++){
// cout << max({dp[i][j][0] , dp[i][j][1] , dp[i][j][2]});
// }
// cout << '\n';
// }
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... |