Submission

Status:

PPPPPP-----

Subtask/Task Score:

60/100

Score: 60

User: purihorharin

Problemset: ตั้งฐานทัพ

Language: c

Time: 0.037 second

Submitted On: 2026-03-19 23:05:51

#include <stdio.h>
#include <stdbool.h>
#include <string.h>

int ncol, nrow;

int dfs (int r, int c, char (*map)[ncol+1]) {
    if (r < 0 || r >= nrow || c < 0 || c >= ncol) return 0;
    else if (map[r][c] != '.') return 0;
    
    map[r][c] = '*';
    return (
        +dfs(r-1, c-1, map)
        +dfs(r-1, c, map)
        +dfs(r-1, c+1, map)
        +dfs(r, c-1, map)
        +dfs(r, c+1, map)
        +dfs(r+1, c-1, map)
        +dfs(r+1, c, map)
        +dfs(r+1, c+1, map)
        +1
    );
}

int main () {
    scanf("%d%d", &ncol, &nrow);
    char map[nrow][ncol+1];
    getchar();
    fread(map, ncol+1, nrow, stdin);

    int max = 0;
    for (int r = 0; r < nrow; r++) {
        for (int c = 0; c < ncol; c++) {
            int result = dfs(r, c, map);
            if (result > max) {
                max = result;
            }
        }
    }
    printf("%d", max);
}