-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathP10285.cpp
50 lines (47 loc) · 1.29 KB
/
P10285.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
#include <iostream>
#include <stdio.h>
int main() {
int N, R, C, heights[10000], runs[10000]; // idx y*C+x
std::string s;
std::cin >> N;
for(int cas = 1; cas <= N; ++cas) {
std::cin >> s >> R >> C; // r lines:
for(int y = 0; y < R; ++y) {
for(int x = 0; x < C; ++x) {
int idx = y*C+x;
std::cin >> heights[idx];
runs[idx] = 1;
}
}
int longestRun = 1;
bool improved = true;
while(improved) {
improved = false;
for(int y = 0; y < R; ++y) {
for(int x = 0; x < C; ++x) {
int idx = y*C+x;
if(x > 0 && heights[y*C+x-1] < heights[idx] && runs[y*C+x-1]+1 > runs[idx]) {
improved = true;
runs[idx] = runs[y*C+x-1]+1;
}
if(x < C-1 && heights[y*C+x+1] < heights[idx] && runs[y*C+x+1]+1 > runs[idx]) {
improved = true;
runs[idx] = runs[y*C+x+1]+1;
}
if(y > 0 && heights[(y-1)*C+x] < heights[idx] && runs[(y-1)*C+x]+1 > runs[idx]) {
improved = true;
runs[idx] = runs[(y-1)*C+x]+1;
}
if(y < R-1 && heights[(y+1)*C+x] < heights[idx] && runs[(y+1)*C+x]+1 > runs[idx]) {
improved = true;
runs[idx] = runs[(y+1)*C+x]+1;
}
if(runs[idx] > longestRun)
longestRun = runs[idx];
} // for x
} // for y
} // while improved
std::cout << s << ": " << longestRun << std::endl;
}
return 0;
}