Submission #837168

# Submission time Handle Problem Language Result Execution time Memory
837168 2023-08-25T06:25:40 Z _martynas The Kingdom of JOIOI (JOI17_joioi) C++11
15 / 100
4000 ms 464 KB
#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) {
        // if(count(heights.begin(), heights.end(), 0) == w) return;
        // if(count(heights.begin(), heights.end(), h) == w) return;
        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() ? 0 : 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) {
      |        ~~~~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 46 ms 316 KB Output is correct
4 Correct 21 ms 212 KB Output is correct
5 Correct 46 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 47 ms 340 KB Output is correct
8 Correct 52 ms 340 KB Output is correct
9 Correct 45 ms 212 KB Output is correct
10 Correct 45 ms 212 KB Output is correct
11 Correct 45 ms 340 KB Output is correct
12 Correct 46 ms 340 KB Output is correct
13 Correct 45 ms 340 KB Output is correct
14 Correct 46 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 46 ms 316 KB Output is correct
4 Correct 21 ms 212 KB Output is correct
5 Correct 46 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 47 ms 340 KB Output is correct
8 Correct 52 ms 340 KB Output is correct
9 Correct 45 ms 212 KB Output is correct
10 Correct 45 ms 212 KB Output is correct
11 Correct 45 ms 340 KB Output is correct
12 Correct 46 ms 340 KB Output is correct
13 Correct 45 ms 340 KB Output is correct
14 Correct 46 ms 464 KB Output is correct
15 Execution timed out 4027 ms 340 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 46 ms 316 KB Output is correct
4 Correct 21 ms 212 KB Output is correct
5 Correct 46 ms 340 KB Output is correct
6 Correct 10 ms 340 KB Output is correct
7 Correct 47 ms 340 KB Output is correct
8 Correct 52 ms 340 KB Output is correct
9 Correct 45 ms 212 KB Output is correct
10 Correct 45 ms 212 KB Output is correct
11 Correct 45 ms 340 KB Output is correct
12 Correct 46 ms 340 KB Output is correct
13 Correct 45 ms 340 KB Output is correct
14 Correct 46 ms 464 KB Output is correct
15 Execution timed out 4027 ms 340 KB Time limit exceeded
16 Halted 0 ms 0 KB -