Submission #143072

# Submission time Handle Problem Language Result Execution time Memory
143072 2019-08-12T21:56:59 Z godwind The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1374 ms 54976 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
//#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>
                        
using namespace std;
                        
template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}
                        
template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define ghost signed
#define left left228
#define right right228
#define complex complex228
#define count count228
#define sin sin228
#define list list228

const int N = 2003;
const int INF = 1e9 + 228;

int res = INF;
int n, m;
int a[N][N];
int left[N], right[N];
int mn = INF, mx = 0;

void solve() {
	int l = -1, r = mx - mn;
	while (r - l > 1) {
		int mid = (l + r) >> 1;
		int x = mid;
		for (int i = 1; i <= n; ++i) {
			left[i] = 0, right[i] = m + 1;
			for (int j = 1; j <= m; ++j) {
				if (a[i][j] > mn + x && right[i] == m + 1) right[i] = j - 1;
				if (a[i][j] < mx - x) left[i] = j;
			}
		}
		bool OK1 = 1, OK2 = 1;
		int last1 = left[1], last2 = right[1];
		if (left[1] > right[1]) OK1 = OK2 = 0;
		for (int i = 2; i <= n; ++i) {
			if (max(last1, left[i]) > right[i]) OK1 = 0;
			uax(last1, left[i]);
			if (min(last2, right[i]) < left[i]) OK2 = 0;
			uin(last2, right[i]);
		}
		if (OK1 || OK2) r = mid;
		else l = mid;
	}
	uin(res, r);
}

ghost main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			uax(mx, a[i][j]);
			uin(mn, a[i][j]);
		}
	}
	res = mx - mn;
	solve();
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m / 2; ++j) {
			swap(a[i][j], a[i][m - j + 1]);
		}
	}
	solve();
	cout << res << '\n';
    return 0;
} // kek ;
// Ого! Кажетсья это $#@!
 

















# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 1400 KB Output is correct
17 Correct 11 ms 1272 KB Output is correct
18 Correct 11 ms 1272 KB Output is correct
19 Correct 13 ms 1272 KB Output is correct
20 Correct 12 ms 1136 KB Output is correct
21 Correct 14 ms 1656 KB Output is correct
22 Correct 13 ms 1724 KB Output is correct
23 Correct 16 ms 1656 KB Output is correct
24 Correct 12 ms 1528 KB Output is correct
25 Correct 18 ms 1656 KB Output is correct
26 Correct 14 ms 1656 KB Output is correct
27 Correct 15 ms 1656 KB Output is correct
28 Correct 14 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 380 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 1400 KB Output is correct
17 Correct 11 ms 1272 KB Output is correct
18 Correct 11 ms 1272 KB Output is correct
19 Correct 13 ms 1272 KB Output is correct
20 Correct 12 ms 1136 KB Output is correct
21 Correct 14 ms 1656 KB Output is correct
22 Correct 13 ms 1724 KB Output is correct
23 Correct 16 ms 1656 KB Output is correct
24 Correct 12 ms 1528 KB Output is correct
25 Correct 18 ms 1656 KB Output is correct
26 Correct 14 ms 1656 KB Output is correct
27 Correct 15 ms 1656 KB Output is correct
28 Correct 14 ms 1656 KB Output is correct
29 Correct 780 ms 37472 KB Output is correct
30 Correct 816 ms 37648 KB Output is correct
31 Correct 1016 ms 39284 KB Output is correct
32 Correct 768 ms 39264 KB Output is correct
33 Correct 601 ms 34168 KB Output is correct
34 Correct 907 ms 39248 KB Output is correct
35 Correct 1092 ms 54808 KB Output is correct
36 Correct 887 ms 49720 KB Output is correct
37 Correct 1374 ms 54976 KB Output is correct