#include <bits/stdc++.h>
using namespace std;
const int mxn = 2005;
const int inf = 2e9;
int h, w;
int a[mxn][mxn];
int best = inf;
vector<int> heights;
void recur() {
if(heights.size() == w) {
int ioimx = 0, ioimn = inf/2, joimx = 0, joimn = inf/2;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
if(i < heights[j]) {
ioimx = max(ioimx, a[i][j]);
ioimn = min(ioimn, a[i][j]);
}
else {
joimx = max(joimx, a[i][j]);
joimn = min(joimn, a[i][j]);
}
}
}
best = min(best, max(ioimx-ioimn, joimx-joimn));
return;
}
for(int i = (heights.empty() ? 1 : heights.back()); i <= h; i++) {
heights.push_back(i);
recur();
heights.pop_back();
}
}
int main(int argc, char const *argv[]) {
cin >> h >> w;
for(int i = 0; i < h; i++) {
for(int j = 0; j < w; j++) {
cin >> a[i][j];
}
}
recur();
for(int i = 0; i < h; i++) reverse(a[i], a[i]+w);
recur();
cout << best << "\n";
return 0;
}
Compilation message
joioi.cpp: In function 'void recur()':
joioi.cpp:14:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
14 | if(heights.size() == w) {
| ~~~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
24 ms |
340 KB |
Output is correct |
4 |
Correct |
11 ms |
340 KB |
Output is correct |
5 |
Incorrect |
23 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
24 ms |
340 KB |
Output is correct |
4 |
Correct |
11 ms |
340 KB |
Output is correct |
5 |
Incorrect |
23 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
24 ms |
340 KB |
Output is correct |
4 |
Correct |
11 ms |
340 KB |
Output is correct |
5 |
Incorrect |
23 ms |
340 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |