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>
#define FOR(i, x, n) for(int i = x; i < n; i++)
#define F0R(i, n) FOR(i, 0, n)
#define ROF(i, x, n) for(int i = n - 1; i >= x; i--)
#define R0F(i, n) ROF(i, 0, n)
#define WTF cout << "WTF" << endl
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define F first
#define S second
#define PB push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<int, PII> PPI;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
const int N = 3000 + 7;
const int LOG = 20;
const int INF = 1e9 + 7;
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
int n,m;
string pic[N];
int dp[N][N][3];
int main() {
IOS;
cin >> n >> m;
FOR(i, 1, n + 1) {
cin >> pic[i];
pic[i] = " " + pic[i];
}
FOR(i, 1, n + 1) FOR(j, 1, m + 1) {
dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
if(pic[i][j - 1] == 'R' && pic[i][j] == 'G' && pic[i][j + 1] == 'W')
dp[i][j][1] = max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][1]) + 1;
if(pic[i - 1][j] == 'R' && pic[i][j] == 'G' && pic[i + 1][j] == 'W')
dp[i][j][2] = max(dp[i - 1][j + 1][0], dp[i - 1][j + 1][2]) + 1;
}
int ans = 0;
FOR(i, 1, n + 1)
ans += max({dp[i][1][0], dp[i][1][1], dp[i][1][2]});
FOR(j, 2, m + 1)
ans += max({dp[n][j][0], dp[n][j][1], dp[n][j][2]});
cout << ans;
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... |