-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10285.cpp
71 lines (58 loc) · 1.66 KB
/
10285.cpp
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
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
struct Node {
int x, y;
} nodes[10000];
int lenn;
int hill[102][102], ll[102][102];
bool compareNode(const Node &A, const Node &B) { return hill[A.x][A.y] > hill[B.x][B.y]; }
int main(void)
{
int T, R, C, ml, x, y, l;
char name[1024];
for (int i = 0; i < 102; ++i) {
memset(hill[i], 0, sizeof(hill[i]));
memset(ll[i], 0, sizeof(ll[i]));
}
scanf("%d", &T);
while (T--) {
scanf("%s %d %d", name, &R, &C);
lenn = 0;
for (int i = 0; i < 102; ++i) {
memset(hill[i], 0, sizeof(hill[i]));
memset(ll[i], 0, sizeof(ll[i]));
}
for (int i = 1; i <= R; ++i)
for (int j = 1; j <= C; ++j) {
scanf("%d", &hill[i][j]);
nodes[lenn].x = i;
nodes[lenn++].y = j;
ll[i][j] = 1;
}
sort(nodes, nodes + lenn, compareNode);
ml = 0;
for (int i = 1; i < lenn; ++i) {
x = nodes[i].x;
y = nodes[i].y;
l = ll[x][y];
if (hill[x + 1][y] > hill[x][y]) {
l = max(l, ll[x + 1][y] + 1);
}
if (hill[x - 1][y] > hill[x][y]) {
l = max(l, ll[x - 1][y] + 1);
}
if (hill[x][y + 1] > hill[x][y]) {
l = max(l, ll[x][y + 1] + 1);
}
if (hill[x][y - 1] > hill[x][y]) {
l = max(l, ll[x][y - 1] + 1);
}
ll[x][y] = l;
ml = max(ml, l);
}
printf("%s: %d\n", name, ml);
}
return 0;
}