답안 #68260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68260 2018-08-16T10:26:53 Z Nurlykhan The Kingdom of JOIOI (JOI17_joioi) C++17
60 / 100
1532 ms 263168 KB
#include <bits/stdc++.h>

#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) int(v.size())
#define pii pair<int, int>
#define mp make_pair
#define f first
#define ll long long
#define ld long double
#define s second
#define vec vector<int>

using namespace std;

const int N = (int) 2e3 + 100;
const int M = (int) 2018 * 2018;
const int K = (int) 10;
const int INF = (int) 1e9 + 7;
const int mod = (int) 998244353;
const ld EPS = (ld) 1e-9;
const ll LINF = (ll) 1e18;

int n, m;
vector<vector<int> > a;
int mx;
int pref[N][N], suff_max[N][N], suff_min[N][N];

void precalc() {
	// global max
	int cur_n = sz(a);
	int cur_m = sz(a[0]);
	mx = 0;
	for (int i = 0; i < cur_n; i++) {
		for (int j = 0; j < cur_m; j++) {
			mx = max(mx, a[i][j]);
		}
	}
	for (int i = 0; i < cur_n; i++) {
		for (int j = 0; j < cur_m; j++) {
			pref[i][j] = a[i][j];
			if (j > 0) 
				pref[i][j] = min(pref[i][j], pref[i][j - 1]);
		}
		suff_min[i][cur_m] = INF;
		suff_max[i][cur_m] = 0;
		for (int j = cur_m - 1; j >= 0; j--) {
			suff_max[i][j] = max(a[i][j], suff_max[i][j + 1]);
			suff_min[i][j] = min(a[i][j], suff_min[i][j + 1]);
		}
	}
}

bool ok(int diff) {
	int cur_n = sz(a);
	int cur_m = sz(a[0]);
	int ptr = cur_m - 1;
	int max_val = mx;
	int mn = INF, mx = 0;
	for (int i = 0; i < cur_n; i++) {
		while (ptr >= 0 && max_val > diff + pref[i][ptr]) {
			ptr--;
		}
		mn = min(mn, suff_min[i][ptr + 1]);
		mx = max(mx, suff_max[i][ptr + 1]);
	}
	return mx - mn <= diff;
}

void mirror() {
	for (int i = 0; i < n / 2; i++) {
		for (int j = 0; j < m; j++) {
			swap(a[i][j], a[n - 1 - i][j]);
		}
	}
}

int b[N][N];

void rotate() {
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			b[j][n - i - 1] = a[i][j];
		}
	}
	swap(n, m);
	a.clear();
	for (int i = 0; i < n; i++) {
		a.pb(vector<int>(m));
		for (int j = 0; j < m; j++) {
			a[i][j] = b[i][j];
		}
	}
}

int main() {
	#ifdef sony
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	srand(time(0));
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		a.pb(vector<int>(m));
		for (int j = 0; j < m; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	int ans = INF;
	for (int i = 0; i < 4; i++) {
		precalc();
		int l = 1, r = ans - 1;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (ok(mid)) {
				r = mid - 1;
				ans = mid;
			} else {
				l = mid + 1;
			}
		}
		mirror();
		precalc();
	    l = 1, r = ans - 1;
		while (l <= r) {
			int mid = (l + r) / 2;
			if (ok(mid)) {
				r = mid - 1;
				ans = mid;
			} else {
				l = mid + 1;
			}
		}
		mirror();
		rotate();
	}
	cout << ans;
	return 0;	
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:106:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i][j]);
    ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 3 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 708 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
11 Correct 3 ms 740 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 3 ms 836 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 3 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 708 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
11 Correct 3 ms 740 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 3 ms 836 KB Output is correct
15 Correct 5 ms 3812 KB Output is correct
16 Correct 12 ms 4580 KB Output is correct
17 Correct 15 ms 4580 KB Output is correct
18 Correct 16 ms 4580 KB Output is correct
19 Correct 17 ms 4580 KB Output is correct
20 Correct 16 ms 4580 KB Output is correct
21 Correct 16 ms 4580 KB Output is correct
22 Correct 16 ms 4600 KB Output is correct
23 Correct 16 ms 4600 KB Output is correct
24 Correct 15 ms 4600 KB Output is correct
25 Correct 17 ms 4600 KB Output is correct
26 Correct 19 ms 4600 KB Output is correct
27 Correct 17 ms 4600 KB Output is correct
28 Correct 19 ms 4600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Correct 2 ms 616 KB Output is correct
5 Correct 3 ms 616 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 3 ms 692 KB Output is correct
8 Correct 2 ms 692 KB Output is correct
9 Correct 2 ms 708 KB Output is correct
10 Correct 2 ms 708 KB Output is correct
11 Correct 3 ms 740 KB Output is correct
12 Correct 2 ms 832 KB Output is correct
13 Correct 2 ms 832 KB Output is correct
14 Correct 3 ms 836 KB Output is correct
15 Correct 5 ms 3812 KB Output is correct
16 Correct 12 ms 4580 KB Output is correct
17 Correct 15 ms 4580 KB Output is correct
18 Correct 16 ms 4580 KB Output is correct
19 Correct 17 ms 4580 KB Output is correct
20 Correct 16 ms 4580 KB Output is correct
21 Correct 16 ms 4580 KB Output is correct
22 Correct 16 ms 4600 KB Output is correct
23 Correct 16 ms 4600 KB Output is correct
24 Correct 15 ms 4600 KB Output is correct
25 Correct 17 ms 4600 KB Output is correct
26 Correct 19 ms 4600 KB Output is correct
27 Correct 17 ms 4600 KB Output is correct
28 Correct 19 ms 4600 KB Output is correct
29 Correct 1002 ms 81536 KB Output is correct
30 Correct 1008 ms 102572 KB Output is correct
31 Correct 1088 ms 126960 KB Output is correct
32 Correct 1268 ms 149992 KB Output is correct
33 Correct 942 ms 167680 KB Output is correct
34 Correct 1258 ms 193432 KB Output is correct
35 Correct 1532 ms 232220 KB Output is correct
36 Runtime error 1137 ms 263168 KB Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience.
37 Halted 0 ms 0 KB -