#include <bits/stdc++.h>
#define task "D"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 3002;
int n, m, dp[N][3];
bool up[N][N], ri[N][N];
string s[N];
int main()
{
#ifdef HynDuf
freopen(task".in", "r", stdin);
//freopen(task".out", "w", stdout);
#else
ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
cin >> n >> m;
rep(i, 1, n)
{
cin >> s[i];
s[i] = '0' + s[i];
}
rep(i, 1, n) rep(j, 1, m)
{
if (i > 1 && i < n) up[i][j] = (s[i][j] == 'G' && s[i - 1][j] == 'R' && s[i + 1][j] == 'W');
if (j > 1 && j < m) ri[i][j] = (s[i][j] == 'G' && s[i][j - 1] == 'R' && s[i][j + 1] == 'W');
}
int ans = 0;
rep(diag, 2, m)
{
int i = 1, j = diag;
rep(t, 0, n) dp[t][0] = dp[t][1] = dp[t][2] = 0;
rep(t, 1, n)
{
if (up[i][j]) dp[t][1] = max(dp[t - 1][0], dp[t - 1][2]) + 1;
if (ri[i][j]) dp[t][2] = max(dp[t - 1][0], dp[t - 1][1]) + 1;
dp[t][0] = max({dp[t - 1][0], dp[t - 1][1], dp[t - 1][2]});
i++, j--;
if (i == n || j == 1)
{
ans += max({dp[t][0], dp[t][1], dp[t][2]});
break;
}
}
}
rep(diag, 2, n)
{
int i = diag, j = m;
rep(t, 1, n)
{
if (up[i][j]) dp[t][1] = max(dp[t - 1][0], dp[t - 1][2]) + 1;
if (ri[i][j]) dp[t][2] = max(dp[t - 1][0], dp[t - 1][1]) + 1;
dp[t][0] = max({dp[t - 1][0], dp[t - 1][1], dp[t - 1][2]});
i++, j--;
if (i == n || j == 1)
{
ans += max({dp[t][0], dp[t][1], dp[t][2]});
break;
}
}
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |