제출 #531590

#제출 시각아이디문제언어결과실행 시간메모리
531590erkeDango Maker (JOI18_dango_maker)C++11
100 / 100
275 ms18068 KiB
#include <bits/stdc++.h>
using namespace std;

const int N = 3010;

int n, m;
char a[N][N];

bool chcol(int x, int y) {
  if (a[x][y] == 'R' && a[x + 1][y] == 'G' && a[x + 2][y] == 'W') return true;
  return false;
}

bool chrow(int x, int y) {
  if (a[x][y] == 'R' && a[x][y + 1] == 'G' && a[x][y + 2] == 'W') return true;
  return false;
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
  for (int j = 1; j <= m; j++) {
    cin >> a[i][j];
  }
  int ans = 0;
  for (int t = 2; t <= n + m - 2; t++) {
    vector<vector<int>> dp(3, vector<int>(3));
    int pos = 0;
    for (int j = t > n ? t - n : 1; j < min(t, m + 1); j++) {
      int i = t - j;
      pos++;
      int cur = pos % 3, prv = (pos - 1 + 3) % 3, PRV = (pos - 2 + 3) % 3;
      dp[cur][0] = max({dp[prv][0], dp[prv][1], dp[prv][2]});
      if (chrow(i, j)) dp[cur][1] = max({dp[prv][0], dp[prv][1], dp[prv][2]}) + 1;
      if (chcol(i, j)) dp[cur][2] = max({dp[PRV][0], dp[PRV][2], dp[prv][2]}) + 1;
    }
    int cur = pos % 3;
    ans += max({dp[cur][0], dp[cur][1], dp[cur][2]});
  }
  cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...