Submission #650758

#TimeUsernameProblemLanguageResultExecution timeMemory
650758ShinDango Maker (JOI18_dango_maker)C++14
100 / 100
246 ms141708 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair

using namespace std;
template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

const int N = 5e3 + 7;
char a[N][N];
int dp[N][N][3];

signed main() {
  cin.tie(0)->sync_with_stdio(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];
    }
  }
  int res = 0;
  for (int i = 1; i <= n; i ++) {
    for (int j = 1; j <= m; j ++) {
      dp[i][j][0] = max({dp[i - 1][j + 1][0], dp[i - 1][j + 1][1], dp[i - 1][j + 1][2]});
      if (a[i][j] == 'G' && a[i][j - 1] == 'R' && a[i][j + 1] == 'W') {
        maximize(dp[i][j][1], max(dp[i - 1][j + 1][1], dp[i - 1][j + 1][0]) + 1);
      }
      if (a[i][j] == 'G' && a[i - 1][j] == 'R' && a[i + 1][j] == 'W') {
        maximize(dp[i][j][2], max(dp[i - 1][j + 1][2], dp[i - 1][j + 1][0]) + 1);
      }
      if (j == 1 || i == n) {
        res += max({dp[i][j][0], dp[i][j][1], dp[i][j][2]});
      }
    }
  }
  cout << res;
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...