답안 #158114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158114 2019-10-14T19:41:49 Z ZwariowanyMarcin The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1235 ms 70504 KB
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl;
#define ios cin.tie(0); ios_base::sync_with_stdio(0)	
	
		
using namespace std;

int n, m;
int a[2002][2002], p[2002][2002];
int ans = 1000000001;
int maks;
int row, col;

void obrot() {
	FOR(i, 1, n)
		FOR(j, 1, m)
			p[j][n - i + 1] = a[i][j];
	int rr = col;
	int cc = n - row + 1;
	swap(n, m);
	row = rr;
	col = cc;
	FOR(i, 1, n)
		FOR(j, 1, m) 
			a[i][j] = p[i][j];
}

int bad[2002];

bool ok(int w) {
	int mini = maks - w;
	FOR(i, 1, n + 1)
		bad[i] = 0;
	for(int i = n; 1 <= i; --i) {
		for(int j = m; 1 <= j; --j) {
			if(a[i][j] < mini) {
				bad[i] = j;
				break;
			}
		}
		bad[i] = max(bad[i], bad[i + 1]);
	}
	if(bad[row] >= col)
		return 0;
	int Max = -1;
	int Min = 1e9 + 111;
	FOR(i, 1, n)
		FOR(j, 1, m) {
			if(j <= bad[i]) {
				Max = max(Max, a[i][j]);
				Min = min(Min, a[i][j]);
			}
		}
	//cout << Max << " " << Min << " " << w << endl;
	return Max - Min <= w;
}

void solve() {
	int l = 0;
	int r = 1000000000;
	while(l < r) {
		int m = (l + r) / 2;
		if(ok(m))
			r = m;
		else
			l = m + 1;
	}
	ans = min(ans, l);
}
	
					
int main() {	
	scanf("%d %d", &n, &m);
	FOR(i, 1, n)
		FOR(j, 1, m) {
			scanf("%d", &a[i][j]);
			if(a[i][j] > maks) {
				maks = a[i][j];
				row = i;
				col = j;
			}
		}
	int k = 4;
	while(k--) {
		obrot();
		
		/*FOR(i, 1, n) {
			FOR(j, 1, m)
				cout << a[i][j] << " ";
			cout << endl;
		}
		
		printf("\n\n");
		*/
		solve();
	}
	printf("%d", ans);
	
				
	return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:84: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:87: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 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 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 504 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
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 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 504 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 4 ms 2040 KB Output is correct
16 Correct 11 ms 2296 KB Output is correct
17 Correct 14 ms 2552 KB Output is correct
18 Correct 14 ms 2552 KB Output is correct
19 Correct 14 ms 2552 KB Output is correct
20 Correct 13 ms 2424 KB Output is correct
21 Correct 17 ms 2680 KB Output is correct
22 Correct 16 ms 2680 KB Output is correct
23 Correct 16 ms 2680 KB Output is correct
24 Correct 14 ms 2680 KB Output is correct
25 Correct 15 ms 2680 KB Output is correct
26 Correct 16 ms 2680 KB Output is correct
27 Correct 16 ms 2680 KB Output is correct
28 Correct 16 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 420 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 504 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 4 ms 2040 KB Output is correct
16 Correct 11 ms 2296 KB Output is correct
17 Correct 14 ms 2552 KB Output is correct
18 Correct 14 ms 2552 KB Output is correct
19 Correct 14 ms 2552 KB Output is correct
20 Correct 13 ms 2424 KB Output is correct
21 Correct 17 ms 2680 KB Output is correct
22 Correct 16 ms 2680 KB Output is correct
23 Correct 16 ms 2680 KB Output is correct
24 Correct 14 ms 2680 KB Output is correct
25 Correct 15 ms 2680 KB Output is correct
26 Correct 16 ms 2680 KB Output is correct
27 Correct 16 ms 2680 KB Output is correct
28 Correct 16 ms 2680 KB Output is correct
29 Correct 996 ms 31692 KB Output is correct
30 Correct 960 ms 31896 KB Output is correct
31 Correct 1052 ms 54804 KB Output is correct
32 Correct 1030 ms 54776 KB Output is correct
33 Correct 890 ms 51576 KB Output is correct
34 Correct 1046 ms 54868 KB Output is correct
35 Correct 1235 ms 70452 KB Output is correct
36 Correct 1053 ms 65144 KB Output is correct
37 Correct 1199 ms 70504 KB Output is correct