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;
const int mod= 1e9 +7;
const int N=1e5*4;
void solve(){
int n,m,k;
cin>>n>>m;
char arr[n+5][n+5];
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
cin>>arr[i][j];
}
}
int ans = 0;
for(int j = 1;j<=m;j++){
int ind = 1,x = 1,y = j;
vector<vector<int>>dp(max(n+1,j+1),{0,0,0});
while(x<=n&&y>=1){
dp[ind][0] = max({dp[ind-1][0],dp[ind-1][1],dp[ind-1][2]});
if(arr[x][y-1]=='R'&&arr[x][y]=='G'&&arr[x][y+1]=='W')dp[ind][1] = max(dp[ind-1][0],dp[ind-1][1]) + 1;
if(arr[x-1][y]=='R'&&arr[x][y]=='G'&&arr[x+1][y]=='W')dp[ind][2] = max(dp[ind-1][0],dp[ind-1][2]) + 1;
x++;y--;ind++;
}
ind--;
ans += max({dp[ind][0],dp[ind][1],dp[ind][2]});
}
for(int i = 2;i<=n;i++){
int ind = 1,x = i,y = m;
vector<vector<int>>dp(max(n+1,(m - (i - 1))),{0,0,0});
while(x<=n&&y>=1){
dp[ind][0] = max({dp[ind-1][0],dp[ind-1][1],dp[ind-1][2]});
if(arr[x][y-1]=='R'&&arr[x][y]=='G'&&arr[x][y+1]=='W')dp[ind][1] = max(dp[ind-1][0],dp[ind-1][1]) + 1;
if(arr[x-1][y]=='R'&&arr[x][y]=='G'&&arr[x+1][y]=='W')dp[ind][2] = max(dp[ind-1][0],dp[ind-1][2]) + 1;
x++;y--;ind++;
}
ind--;
ans += max({dp[ind][0],dp[ind][1],dp[ind][2]});
}
cout<<ans<<" ";
//ne spizdil , a adaptiroval
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt;
while(tt--)solve();
}
Compilation message (stderr)
dango_maker.cpp: In function 'void solve()':
dango_maker.cpp:8:10: warning: unused variable 'k' [-Wunused-variable]
8 | int n,m,k;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |