#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
char tab[3005][3005];
int dp[3005][3005][3];
vector <pair<int, int>> ord[6003];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i ++)
{
for(int j = 1; j <= m; j ++) ord[i + j].pb(make_pair(i, j));
}
for(int i=1; i<=n; i++)
{
cin >> s;
for(int j=0; j<m; j++) tab[i][j+1]=s[j];
}
int x=0, y=0;
for(int k = 1; k <= n + m; k ++)
{
bool czy = 1;
for(auto it: ord[k])
{
int i = it.first, j = it.second;
dp[i][j][0]=max({dp[x][y][0], dp[x][y][1], dp[x][y][2]}); //nic
if(tab[i][j]=='W' && tab[i][j-1]=='G' && tab[i][j-2]=='R') //poz
{
if(czy) {
dp[i][j][1]=max({dp[x][y][0], dp[x][y][1], dp[x][y][2]})+1;
}
else {
dp[i][j][1]=max({dp[i-1][j+1][0], dp[i-1][j+1][1], dp[i-1][i+1][2]})+1;
}
}
if(tab[i][j]=='W' && tab[i-1][j]=='G' && tab[i-2][j]=='R') //pion
{
if(czy) {
dp[i][j][1]=max({dp[x][y][0], dp[x][y][1], dp[x][y][2]})+1;
}
else {
dp[i][j][2]=max({dp[i-1][j+1][2], dp[i-1][j+1][0]})+1;
}
}
czy = 0;
x=i, y=j;
}
}
// for(int i=1; i<=n; i++)
// {
// for(int j=1; j<=m; j++)
// {
// cout << dp[i][j][0] << " " << dp[i][j][1] << ' ' << dp[i][j][2] << '\n';
// }
// cout << "\n";
// }
cout << max({dp[n][m][0], dp[n][m][1], dp[n][m][2]}) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
604 KB |
Output is correct |
4 |
Correct |
0 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
600 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Incorrect |
0 ms |
604 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |