50120. Consecutive 1's

難度:2/5 Used Time: 7:20

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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>
#include <stdlib.h>

#define max(a,b) ((a)>(b)?(a):(b))

int n;
int arr[1024][1024] = {0};
int max_len = 0;

void row(){
for(int i = 0; i < n; i++){
int cnt = 0;
for(int j = 0; j < n; j++){
if(arr[i][j] == 1) cnt++;
else{
max_len = max(max_len, cnt);
cnt = 0;
}
}
max_len = max(max_len, cnt);
}
}

void col(){
for(int i = 0; i < n; i++){
int cnt = 0;
for(int j = 0; j < n; j++){
if(arr[j][i] == 1) cnt++;
else{
max_len = max(max_len, cnt);
cnt = 0;
}
}
max_len = max(max_len, cnt);
}
}

void diag(){
for(int i = n - 1; i >= 0; i--){
int x = 0, y = i;
int cnt = 0;
while(x < n && y < n){
if(arr[x][y] == 1) cnt++;
else{
max_len = max(max_len, cnt);
cnt = 0;
}
x++, y++;
}
max_len = max(max_len, cnt);
}
for(int i = 1; i < n; i++){
int x = i, y = 0;
int cnt = 0;
while(x < n && y < n){
if(arr[x][y] == 1) cnt++;
else{
max_len = max(max_len, cnt);
cnt = 0;
}
x++, y++;
}
max_len = max(max_len, cnt);
}
}

int main(){
scanf("%d", &n);
for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d", &arr[i][j]);
row();
col();
diag();
printf("%d\n", max_len);
}


50120. Consecutive 1's
https://aaronlin1229.github.io/judgegirl_50120/
Author
Akizumi
Posted on
July 17, 2023
Licensed under