#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define cd complex<ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pld pair<ld,ld>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n, m;
char c[3005][3005];
ll dp[2][3005][3005];
ll ans[3005][3005];
bool chk[2][3005][3005];
//vector<pair<ll,pll>> T[2][3005][3005];
void solve()
{
cin >> n >> m;
for(int i = 1; i<= n; i++)
{
for(int j = 1; j<= m; j++) cin >> c[i][j];
}
for(int i = 1 ;i<= n; i++)
{
for(int j = 3; j<= m; j++)
{
if(c[i][j-1]=='G'&&c[i][j-1]!=c[i][j-2]&&c[i][j-2]!=c[i][j]&&c[i][j]!=c[i][j-1]) chk[0][i][j] = 1;
}
}
for(int i = 3 ;i<= n; i++)
{
for(int j = 1; j<= m; j++)
{
if(c[i-1][j]=='G'&&c[i-1][j]!=c[i-2][j]&&c[i][j]!=c[i-2][j]&&c[i][j]!=c[i-1][j]) chk[1][i][j] = 1;
}
}
for(int i = 1; i<= n; i++)
{
for(int j = 1; j<= m; j++)
{
dp[1][i][j] = chk[1][i][j]+dp[1][i-1][j+1];
if(i-3>=0) dp[1][i][j] = max(dp[1][i][j], dp[0][i-3][j+3]+chk[1][i][j]);
dp[0][i][j] = max(dp[0][i-1][j+1]+chk[0][i][j],dp[1][i][j]);
//cout << i << " " << j << " " << dp[0][i][j] << " " << dp[1][i][j] << " " << chk[0][i][j] << " " << chk[1][i][j] << " " << dp[0][i-1][j+1]<< "\n";
}
}
ll ans = 0;
for(int i = 1; i<= n; i++)
{
for(int j = 1 ; j<= m; j++)
{
if(j==1||i==n)
{
ans += dp[0][i][j];
}
//cout << i << " " << j << " " << dp[0][i][j] << " " << dp[1][i][j] << " " << chk[0][i][j] << " " << chk[1][i][j] << " " << dp[0][i-1][j+1]<< "\n";
}
}
cout << ans;
}
signed main()
{
//freopen("IN.txt","r",stdin);
//freopen("OUT.txt","w",stdout);
ios_base::sync_with_stdio(NULL) ; cin.tie(nullptr) ; cout.tie(nullptr);
ll t = 1;
//cin >> t;
while(t--)
{
solve();
cout << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |