VaultBy ENSAMIENParrainage
C55 lines

maximum-borders.c

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <stdio.h>

/* #define MAXN 100
#define MAXM 100  // partially accepted */

#define MAXN 1005
#define MAXM 1005  
// accepted , HackerEarth test files can be large. The grid can be up to 1000 × 1000 (sometimes more).


int main() {
    int t, n, m;
    char tab[MAXN][MAXM+1]; // +1 for string terminator when reading rows

    scanf("%d", &t);
    while (t--) {
        scanf("%d %d", &n, &m);

        for (int i = 0; i < n; i++) {
            scanf("%s", tab[i]); // read entire row as string
        }

        int ans = 0;

        // check rows
        for (int i = 0; i < n; i++) {
            int cnt = 0;
            for (int j = 0; j < m; j++) {
                if (tab[i][j] == '#') {
                    cnt++;
                    if (cnt > ans) ans = cnt;
                } else {
                    cnt = 0;
                }
            }
        }

        // check columns
        for (int j = 0; j < m; j++) {
            int cnt = 0;
            for (int i = 0; i < n; i++) {
                if (tab[i][j] == '#') {
                    cnt++;
                    if (cnt > ans) ans = cnt;
                } else {
                    cnt = 0;
                }
            }
        }

        printf("%d\n", ans);
    }

    return 0;
}

    Type at least 2 letters. ↑ ↓ to move, Enter to open.