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 int long long
#define IO ios::sync_with_stdio(0), cin.tie(0)
#define FOR(i, a, b) for (int i = a; i <= b; i++)
using namespace std;
using pii = pair<int, int>;
void dbg() {;}
template<class T, class ...U>
void dbg(T a, U ...b) { cout << a << " "; dbg(b...); }
void ent() { cout << "\n"; }
const int INF = 1e17;
const int N = 105;
char a[N][N];
int vis[N][N];
int ans = 0, res = 0;
int n, m;
void dfs(int x, int y) {
if (x == n + 1) {
ans = max(ans, res);
return;
}
if (y == m + 1) {
dfs(x + 1, 1);
return;
}
if (vis[x][y]) {
dfs(x, y + 1);
return;
}
if (a[x][y] == 'R') {
if (y + 2 <= m && a[x][y + 1] == 'G' && a[x][y + 2] == 'W' && !vis[x][y + 1] && !vis[x][y + 2]) {
vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = true;
res += 1;
dfs(x, y + 3);
vis[x][y] = vis[x][y + 1] = vis[x][y + 2] = false;
res -= 1;
}
if (x + 2 <= n && a[x + 1][y] == 'G' && a[x + 2][y] == 'W' && !vis[x + 1][y] && !vis[x + 2][y]) {
vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = true;
res += 1;
dfs(x, y + 1);
vis[x][y] = vis[x + 1][y] = vis[x + 2][y] = false;
res -= 1;
}
}
dfs(x, y + 1);
}
signed main() {
IO;
cin >> n >> m;
FOR(i, 1, n)
FOR(j, 1, m)
cin >> a[i][j];
dfs(1, 1);
cout << ans << "\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... |