답안 #880528

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880528 2023-11-29T15:29:01 Z frostray8653 Dango Maker (JOI18_dango_maker) C++17
0 / 100
1 ms 416 KB
#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 n, m;

// vertical lines / horizontal line
int ver = 0, hor = 0;
void dfs(int x, int y) {
    vis[x][y] = true;
    if (a[x][y] == 'R') {
        if (x + 2 <= n && a[x + 1][y] == 'G' && a[x + 2][y] == 'W')
            ver += 1;
        if (y + 2 <= m && a[x][y + 1] == 'G' && a[x][y + 2] == 'W')
            hor += 1;
    }
    if (a[x][y] == 'G') {
        if (x - 1 >= 1 && x + 1 <= n && a[x - 1][y] == 'R' && a[x + 1][y] == 'W') {
            if (!vis[x - 1][y])
                dfs(x - 1, y);
            if (!vis[x + 1][y])
                dfs(x + 1, y);
        }
        if (y - 1 >= 1 && y + 1 <= m && a[x][y - 1] == 'R' && a[x][y + 1] == 'W') {
            if (!vis[x][y - 1])
                dfs(x, y - 1);
            if (!vis[x][y + 1])
                dfs(x, y + 1);
        }
    }
    if (a[x][y] == 'W') {
        if (x - 2 >= 1 && a[x - 2][y] == 'R' && a[x - 1][y] == 'W') {
            if (!vis[x - 2][y])
                dfs(x - 2, y);
            if (!vis[x - 1][y])
                dfs(x - 1, y);
        }
        if (y - 2 >= 1 && a[x][y - 2] == 'R' && a[x][y - 1] == 'W') {
            if (!vis[x][y - 2])
                dfs(x, y - 2);
            if (!vis[x][y - 1])
                dfs(x, y - 1);
        }
    }
}

signed main() {
    IO;
    
    cin >> n >> m;
    FOR(i, 1, n)
        FOR(j, 1, m)
            cin >> a[i][j];
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (!vis[i][j]) {
                ver = hor = 0;
                dfs(i, j);
                ans += max(ver, hor);
            }
        }
    }
    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 416 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Incorrect 0 ms 344 KB Output isn't correct
7 Halted 0 ms 0 KB -