Submission #61081

# Submission time Handle Problem Language Result Execution time Memory
61081 2018-07-25T07:45:04 Z gusfring The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
86 ms 7528 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 205;
 
int n, m, mn = 1e9, a[N][N], b[N][N], f[N];
 
bool check0(int x) {
	f[0] = 1e9;
	int _mn, _mx;
	_mn = 1e9, _mx = 0;
	for (int i = 1; i <= n; ++i) {
		int mx = 0; f[i] = 0;
		for (int j = 1; j <= m; ++j) {
			mx = max(mx, b[i][j]);
			if (mx - mn > x) break;
			f[i]++;
		}
		f[i] = min(f[i], f[i - 1]);
		for (int j = f[i] + 1; j <= m; ++j) {
			_mn = min(_mn, b[i][j]);
			_mx = max(_mx, b[i][j]);
		}
	}
	return _mx - _mn <= x;
}
 
bool check1(int x) {
	bool ok = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			b[i][j] = a[i][j];
		}
	}
	ok |= check0(x);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			b[i][j] = a[i][m - j + 1];
		}
	}
	ok |= check0(x);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			b[i][j] = a[n - i + 1][j];
		}
	}
	ok |= check0(x);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			b[i][j] = a[n - i + 1][m - j + 1];
		}
	}
	ok |= check0(x);
	return ok;
}
 
int main() {
	scanf("%d %d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			scanf("%d", &a[i][j]); mn = min(mn, a[i][j]);
		}
	}
 
	int l = 0, r = 1e9;
	while (l < r) {
		int mid = (l + r) >> 1;
		if (check1(mid)) r = mid;
		else l = mid + 1;
	}
	cout << l;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:58:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
joioi.cpp:61:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i][j]); mn = min(mn, a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 3 ms 752 KB Output is correct
7 Correct 3 ms 752 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 3 ms 752 KB Output is correct
10 Correct 3 ms 752 KB Output is correct
11 Correct 3 ms 756 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 3 ms 752 KB Output is correct
7 Correct 3 ms 752 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 3 ms 752 KB Output is correct
10 Correct 3 ms 752 KB Output is correct
11 Correct 3 ms 756 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 5 ms 776 KB Output is correct
16 Correct 19 ms 1204 KB Output is correct
17 Correct 23 ms 1408 KB Output is correct
18 Correct 23 ms 1656 KB Output is correct
19 Correct 23 ms 1944 KB Output is correct
20 Correct 20 ms 2232 KB Output is correct
21 Correct 29 ms 2600 KB Output is correct
22 Correct 31 ms 2988 KB Output is correct
23 Correct 20 ms 3372 KB Output is correct
24 Correct 19 ms 3648 KB Output is correct
25 Correct 32 ms 4120 KB Output is correct
26 Correct 26 ms 4508 KB Output is correct
27 Correct 38 ms 4896 KB Output is correct
28 Correct 28 ms 5284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 360 KB Output is correct
3 Correct 3 ms 608 KB Output is correct
4 Correct 2 ms 608 KB Output is correct
5 Correct 2 ms 752 KB Output is correct
6 Correct 3 ms 752 KB Output is correct
7 Correct 3 ms 752 KB Output is correct
8 Correct 3 ms 752 KB Output is correct
9 Correct 3 ms 752 KB Output is correct
10 Correct 3 ms 752 KB Output is correct
11 Correct 3 ms 756 KB Output is correct
12 Correct 3 ms 760 KB Output is correct
13 Correct 2 ms 764 KB Output is correct
14 Correct 2 ms 768 KB Output is correct
15 Correct 5 ms 776 KB Output is correct
16 Correct 19 ms 1204 KB Output is correct
17 Correct 23 ms 1408 KB Output is correct
18 Correct 23 ms 1656 KB Output is correct
19 Correct 23 ms 1944 KB Output is correct
20 Correct 20 ms 2232 KB Output is correct
21 Correct 29 ms 2600 KB Output is correct
22 Correct 31 ms 2988 KB Output is correct
23 Correct 20 ms 3372 KB Output is correct
24 Correct 19 ms 3648 KB Output is correct
25 Correct 32 ms 4120 KB Output is correct
26 Correct 26 ms 4508 KB Output is correct
27 Correct 38 ms 4896 KB Output is correct
28 Correct 28 ms 5284 KB Output is correct
29 Execution timed out 86 ms 7528 KB Time limit exceeded (wall clock)
30 Halted 0 ms 0 KB -