Submission #158113

# Submission time Handle Problem Language Result Execution time Memory
158113 2019-10-14T19:40:49 Z ZwariowanyMarcin The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
1077 ms 53920 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[2001][2001], p[2001][2001];
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[2001];

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]);
    ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 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 236 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 3 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 504 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 236 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 4 ms 2168 KB Output is correct
16 Correct 12 ms 2424 KB Output is correct
17 Correct 15 ms 2552 KB Output is correct
18 Correct 16 ms 2556 KB Output is correct
19 Correct 15 ms 2552 KB Output is correct
20 Correct 14 ms 2552 KB Output is correct
21 Correct 16 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 2552 KB Output is correct
25 Correct 15 ms 2680 KB Output is correct
26 Correct 16 ms 2680 KB Output is correct
27 Correct 15 ms 2680 KB Output is correct
28 Correct 15 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 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 236 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 6 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 380 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 4 ms 2168 KB Output is correct
16 Correct 12 ms 2424 KB Output is correct
17 Correct 15 ms 2552 KB Output is correct
18 Correct 16 ms 2556 KB Output is correct
19 Correct 15 ms 2552 KB Output is correct
20 Correct 14 ms 2552 KB Output is correct
21 Correct 16 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 2552 KB Output is correct
25 Correct 15 ms 2680 KB Output is correct
26 Correct 16 ms 2680 KB Output is correct
27 Correct 15 ms 2680 KB Output is correct
28 Correct 15 ms 2680 KB Output is correct
29 Correct 1077 ms 53920 KB Output is correct
30 Incorrect 1046 ms 53208 KB Output isn't correct
31 Halted 0 ms 0 KB -