답안 #561210

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
561210 2022-05-12T13:14:49 Z flappybird The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
746 ms 55620 KB
#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 2100
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int arr[MAX][MAX];
pii range[MAX];
int N, M;
bool rchk() {
	int i;
	int mnn = -1;
	bool cc = true;
	for (i = 1; i <= N; i++) {
		if (mnn < range[i].first) mnn = range[i].first;
		else {
			if (mnn >= range[i].second) {
				cc = false;
				break;
			}
		}
	}
	if (cc) return true;
	cc = true;
	mnn = -1;
	for (i = N; i >= 1; i--) {
		if (mnn < range[i].first) mnn = range[i].first;
		else {
			if (mnn >= range[i].second) {
				cc = false;
				break;
			}
		}
	}
	return cc;
}
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> N >> M;
	int i, j;
	int mn = 1000000010;
	int mx = 0;
	for (i = 1; i <= N; i++) {
		for (j = 1; j <= M; j++) {
			cin >> arr[i][j];
			mx = max(arr[i][j], mx);
			mn = min(arr[i][j], mn);
		}
	}
	if (mx == mn) {
		cout << 0 << ln;
		return 0;
	}
	int l, r;
	l = -1;
	r = mx - mn;
	int mid;
	while (r - l > 1) {
		mid = (l + r + 1) / 2;
		bool chk = true;
		for (i = 1; i <= N; i++) {
			range[i] = { 0, M + 1 };
			for (j = 1; j <= M; j++) if (mx - arr[i][j] > mid) range[i].first = j;
			for (j = M; j >= 1; j--) if (arr[i][j] - mn > mid) range[i].second = j;
			if (range[i].first >= range[i].second) {
				chk = false;
				break;
			}
		}
		if (chk) chk = rchk();
		if (!chk) {
			chk = true;
			for (i = 1; i <= N; i++) {
				range[i] = { 0, M + 1 };
				for (j = 1; j <= M; j++) if (arr[i][j] - mn > mid) range[i].first = j;
				for (j = M; j >= 1; j--) if (mx - arr[i][j] > mid) range[i].second = j;
				if (range[i].first >= range[i].second) {
					chk = false;
					break;
				}
			}
			if (chk) chk = rchk();
		}
		if (chk) r = mid;
		else l = mid;
	}
	cout << r << ln;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 7 ms 1532 KB Output is correct
18 Correct 5 ms 1492 KB Output is correct
19 Correct 7 ms 1492 KB Output is correct
20 Correct 6 ms 1360 KB Output is correct
21 Correct 8 ms 1612 KB Output is correct
22 Correct 7 ms 1620 KB Output is correct
23 Correct 9 ms 1624 KB Output is correct
24 Correct 5 ms 1464 KB Output is correct
25 Correct 8 ms 1620 KB Output is correct
26 Correct 8 ms 1608 KB Output is correct
27 Correct 7 ms 1620 KB Output is correct
28 Correct 7 ms 1620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 360 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 7 ms 1532 KB Output is correct
18 Correct 5 ms 1492 KB Output is correct
19 Correct 7 ms 1492 KB Output is correct
20 Correct 6 ms 1360 KB Output is correct
21 Correct 8 ms 1612 KB Output is correct
22 Correct 7 ms 1620 KB Output is correct
23 Correct 9 ms 1624 KB Output is correct
24 Correct 5 ms 1464 KB Output is correct
25 Correct 8 ms 1620 KB Output is correct
26 Correct 8 ms 1608 KB Output is correct
27 Correct 7 ms 1620 KB Output is correct
28 Correct 7 ms 1620 KB Output is correct
29 Correct 439 ms 37908 KB Output is correct
30 Correct 459 ms 38208 KB Output is correct
31 Correct 525 ms 39864 KB Output is correct
32 Correct 364 ms 39828 KB Output is correct
33 Correct 339 ms 34772 KB Output is correct
34 Correct 440 ms 40044 KB Output is correct
35 Correct 535 ms 55520 KB Output is correct
36 Correct 440 ms 50220 KB Output is correct
37 Correct 746 ms 55620 KB Output is correct