Submission #880513

#TimeUsernameProblemLanguageResultExecution timeMemory
880513frostray8653Dango Maker (JOI18_dango_maker)C++17
0 / 100
0 ms348 KiB
#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] = 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][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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...