This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
using namespace std;
template<typename T> void uin(T &a, T b) {
if (b < a) {
a = b;
}
}
template<typename T> void uax(T &a, T b) {
if (b > a) {
a = b;
}
}
#define int long long
#define left left228
#define right right228
#define prev prev228
#define list list228
#define mp make_pair
#define all(v) v.begin(), v.end()
#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define firn(i, n) for (int i = 1; i < (int)n; ++i)
#define x first
#define y second
const int N = 3005;
bool is_right[N][N], is_up[N][N];
char a[N][N];
vector< pair<int, int> > sum[N + N];
int dp[N + N][3];
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> a[i][j];
sum[i + j].push_back({i, j});
}
}
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
if (a[i][j] == 'G') {
if (i - 1 >= 1 && i + 1 <= n && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
is_up[i][j] = 1;
}
if (j - 1 >= 1 && j + 1 <= m && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
is_right[i][j] = 1;
}
}
}
}
int res = 0;
for (int S = 2; S <= n + m; ++S) {
int sz = (int)sum[S].size();
for (int i = 1; i <= sz; ++i) {
dp[i][0] = dp[i][1] = dp[i][2] = 0;
}
dp[0][0] = 0;
for (int i = 1; i <= sz; ++i) {
int x = sum[S][i - 1].first, y = sum[S][i - 1].second;
dp[i][0] = max(dp[i - 1][0], max(dp[i - 1][1], dp[i - 1][2]));
for (int j = 1; j < 3; ++j) {
if (a[x][y] == 'G') {
if (j && ((j == 1 && is_right[x][y]) || (j == 2 && is_up[x][y]))) {
for (int jj = 0; jj < 3; ++jj) {
if (jj != 3 - j) {
uax(dp[i][j], dp[i - 1][jj] + 1);
}
}
}
}
}
}
res += max(dp[sz][0], max(dp[sz][1], dp[sz][2]));
}
cout << res << '\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... |