#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN = 2005;
const int INF = 1000000007;
int n, m, mn = INF, mx;
int l[MAXN] [MAXN];
short c[MAXN] [MAXN];
bool oboji (int d) {
for (int s=0; s<m; s++) {
if (d == 1) {
for (int r=1; r<n; r++) {
if (c[r-1] [s] == 1) {
if (c[r] [s] == 2) return 0;
c[r] [s] = 1;
}
}
} else {
for (int r=n-2; r>=0; r--) {
if (c[r+1] [s] == 1) {
if (c[r] [s] == 2) return 0;
c[r] [s] = 1;
}
}
}
}
for (int r=0; r<n; r++) {
for (int s=m-2; s>=0; s--) {
if (c[r] [s+1] == 1) {
if (c[r] [s] == 2) return 0;
c[r] [s] = 1;
}
}
}
return 1;
}
bool ok (int x) {
memset(c, 0, sizeof c);
int lef = MAXN, rig = -1, hlef, hrig;
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
if (l[i] [j] > mn + x) {
c[i] [j] = 2;
if (j < lef) {
lef = j;
hlef = i;
}
}
if (l[i] [j] < mx - x) {
if (c[i] [j] == 2) return 0;
c[i] [j] = 1;
if (j > rig) {
rig = j;
hrig = i;
}
}
}
}
if (rig < lef) return 1;
if (hlef < hrig) return oboji(1); return oboji(2);
}
bool moze (int x) {
if (ok(x)) return 1;
for (int i=0; i<n; i++) {
reverse(l[i], l[i]+m);
}
return ok(x);
}
int main () {
cin >> n >> m;
for (int i=0; i<n; i++) {
for (int j=0; j<m; j++) {
cin >> l[i] [j];
mn = min(mn, l[i] [j]);
mx = max(mx, l[i] [j]);
}
}
int low = 0, high = INF, mid;
while (low < high) {
mid = (low+high) / 2;
if (moze(mid)) {
high = mid;
} else {
low = mid+1;
}
}
cout << low;
return 0;
}
Compilation message
joioi.cpp: In function 'bool ok(int)':
joioi.cpp:66:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (hlef < hrig) return oboji(1); return oboji(2);
^~
joioi.cpp:66:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if (hlef < hrig) return oboji(1); return oboji(2);
^~~~~~
joioi.cpp:66:2: warning: 'hrig' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (hlef < hrig) return oboji(1); return oboji(2);
^~
joioi.cpp:66:2: warning: 'hlef' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
8184 KB |
Output is correct |
2 |
Correct |
26 ms |
8296 KB |
Output is correct |
3 |
Correct |
35 ms |
8336 KB |
Output is correct |
4 |
Correct |
39 ms |
8448 KB |
Output is correct |
5 |
Correct |
35 ms |
8448 KB |
Output is correct |
6 |
Correct |
38 ms |
8448 KB |
Output is correct |
7 |
Correct |
35 ms |
8448 KB |
Output is correct |
8 |
Correct |
33 ms |
8448 KB |
Output is correct |
9 |
Correct |
37 ms |
8448 KB |
Output is correct |
10 |
Correct |
40 ms |
8492 KB |
Output is correct |
11 |
Correct |
31 ms |
8492 KB |
Output is correct |
12 |
Correct |
41 ms |
8544 KB |
Output is correct |
13 |
Correct |
33 ms |
8544 KB |
Output is correct |
14 |
Correct |
43 ms |
8596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
8184 KB |
Output is correct |
2 |
Correct |
26 ms |
8296 KB |
Output is correct |
3 |
Correct |
35 ms |
8336 KB |
Output is correct |
4 |
Correct |
39 ms |
8448 KB |
Output is correct |
5 |
Correct |
35 ms |
8448 KB |
Output is correct |
6 |
Correct |
38 ms |
8448 KB |
Output is correct |
7 |
Correct |
35 ms |
8448 KB |
Output is correct |
8 |
Correct |
33 ms |
8448 KB |
Output is correct |
9 |
Correct |
37 ms |
8448 KB |
Output is correct |
10 |
Correct |
40 ms |
8492 KB |
Output is correct |
11 |
Correct |
31 ms |
8492 KB |
Output is correct |
12 |
Correct |
41 ms |
8544 KB |
Output is correct |
13 |
Correct |
33 ms |
8544 KB |
Output is correct |
14 |
Correct |
43 ms |
8596 KB |
Output is correct |
15 |
Correct |
31 ms |
8676 KB |
Output is correct |
16 |
Correct |
47 ms |
9612 KB |
Output is correct |
17 |
Correct |
50 ms |
9832 KB |
Output is correct |
18 |
Correct |
69 ms |
10104 KB |
Output is correct |
19 |
Correct |
66 ms |
10468 KB |
Output is correct |
20 |
Correct |
53 ms |
10660 KB |
Output is correct |
21 |
Correct |
68 ms |
11044 KB |
Output is correct |
22 |
Correct |
76 ms |
11536 KB |
Output is correct |
23 |
Correct |
62 ms |
11816 KB |
Output is correct |
24 |
Correct |
72 ms |
12092 KB |
Output is correct |
25 |
Correct |
69 ms |
12720 KB |
Output is correct |
26 |
Correct |
72 ms |
13080 KB |
Output is correct |
27 |
Correct |
78 ms |
13444 KB |
Output is correct |
28 |
Correct |
74 ms |
13720 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
8184 KB |
Output is correct |
2 |
Correct |
26 ms |
8296 KB |
Output is correct |
3 |
Correct |
35 ms |
8336 KB |
Output is correct |
4 |
Correct |
39 ms |
8448 KB |
Output is correct |
5 |
Correct |
35 ms |
8448 KB |
Output is correct |
6 |
Correct |
38 ms |
8448 KB |
Output is correct |
7 |
Correct |
35 ms |
8448 KB |
Output is correct |
8 |
Correct |
33 ms |
8448 KB |
Output is correct |
9 |
Correct |
37 ms |
8448 KB |
Output is correct |
10 |
Correct |
40 ms |
8492 KB |
Output is correct |
11 |
Correct |
31 ms |
8492 KB |
Output is correct |
12 |
Correct |
41 ms |
8544 KB |
Output is correct |
13 |
Correct |
33 ms |
8544 KB |
Output is correct |
14 |
Correct |
43 ms |
8596 KB |
Output is correct |
15 |
Correct |
31 ms |
8676 KB |
Output is correct |
16 |
Correct |
47 ms |
9612 KB |
Output is correct |
17 |
Correct |
50 ms |
9832 KB |
Output is correct |
18 |
Correct |
69 ms |
10104 KB |
Output is correct |
19 |
Correct |
66 ms |
10468 KB |
Output is correct |
20 |
Correct |
53 ms |
10660 KB |
Output is correct |
21 |
Correct |
68 ms |
11044 KB |
Output is correct |
22 |
Correct |
76 ms |
11536 KB |
Output is correct |
23 |
Correct |
62 ms |
11816 KB |
Output is correct |
24 |
Correct |
72 ms |
12092 KB |
Output is correct |
25 |
Correct |
69 ms |
12720 KB |
Output is correct |
26 |
Correct |
72 ms |
13080 KB |
Output is correct |
27 |
Correct |
78 ms |
13444 KB |
Output is correct |
28 |
Correct |
74 ms |
13720 KB |
Output is correct |
29 |
Correct |
2331 ms |
49980 KB |
Output is correct |
30 |
Correct |
2490 ms |
72256 KB |
Output is correct |
31 |
Correct |
2745 ms |
95496 KB |
Output is correct |
32 |
Correct |
2256 ms |
118516 KB |
Output is correct |
33 |
Correct |
2144 ms |
136780 KB |
Output is correct |
34 |
Correct |
2755 ms |
161936 KB |
Output is correct |
35 |
Correct |
3669 ms |
200708 KB |
Output is correct |
36 |
Correct |
2738 ms |
234316 KB |
Output is correct |
37 |
Execution timed out |
4009 ms |
263168 KB |
Time limit exceeded |