Submission #157138

# Submission time Handle Problem Language Result Execution time Memory
157138 2019-10-09T17:16:13 Z staniewzki The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
2 ms 376 KB
#include<bits/stdc++.h>
using namespace std;

ostream& operator<<(ostream &out, string str) {
	for(char c : str) out << c;
	return out;
}
 
template<class L, class R> ostream& operator<<(ostream &out, pair<L, R> p) {
	return out << "(" << p.first << ", " << p.second << ")";
}
 
template<class T> auto operator<<(ostream &out, T a) -> decltype(a.begin(), out) {
	out << "{";
	for(auto it = a.begin(); it != a.end(); it = next(it))
		out << (it != a.begin() ? ", " : "") << *it;
	return out << "}";
}
 
void dump() { cerr << "\n"; }
template<class T, class... Ts> void dump(T a, Ts... x) {
	cerr << a << ", ";
	dump(x...);
}
 
#ifdef DEBUG
#  define debug(...) cerr << "[" #__VA_ARGS__ "]: ", dump(__VA_ARGS__)
#else
#  define debug(...) false
#endif
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ST first
#define ND second
 
template<class T> int size(T && a) { return a.size(); }

using LL = long long;
using PII = pair<int, int>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int n, m;
	cin >> n >> m;

	vector<vector<int>> a(n, vector<int>(m));
	int mx = 0, mn = 1e9;
	REP(i, n) REP(j, m) {
		cin >> a[i][j];
		mx = max(mx, a[i][j]);
		mn = min(mn, a[i][j]);
	}

	auto check = [&](int h) {
		REP(t, 4) {
			int l = 0, r = m;
			bool ok = true;
			REP(i, n) {
				l = 0;
				REP(j, m) {
					if(a[i][j] - mn <= h && mx - a[i][j] > h) l = max(l, j);
					if(a[i][j] - mn > h && mx - a[i][j] <= h) r = min(r, j - 1);
				}
				if(l > r) ok = false;
			}
			if(ok) return true;
			reverse(a.begin(), a.end());
			if(t % 2) REP(i, n) reverse(a[i].begin(), a[i].end());
		}
		return false;
	};
	
	int l = 0, r = mx - mn;
	while(l < r) {
		int m = (l + r) / 2;
		if(check(m))
			r = m;
		else
			l = m + 1;
	}

	cout << l << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 252 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -