Submission #236425

# Submission time Handle Problem Language Result Execution time Memory
236425 2020-06-02T08:00:27 Z GioChkhaidze The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1054 ms 70648 KB
#include <bits/stdc++.h>
using namespace std;
const int N=2004;
int n,m,Max,Min,ans;
int a[N][N],b[N][N];

bool check(int x) {
	int Col=0;
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=m; j++)
			if (Max-x>a[i][j]) Col=max(Col,j);
		for (int j=1; j<=Col; j++)
			if (Min+x<a[i][j]) return false;
	}
	
	return true;
} 

void G() {
	int l=0,r=Max-Min,mid,res=-1;
	while (l<=r) {
		mid=(l+r)/2;
		if (check(mid))
			r=mid-1,res=mid;
				else
			l=mid+1;
	}
	if (res==-1) return ;
	ans=min(ans,res);
}

void Rotate() {
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++)
			b[i][j]=a[i][j];
		
	for (int i=1; i<=m; i++)
		for (int j=1; j<=n; j++) 
			a[i][j]=b[j][m-i+1];
		
	swap(n,m);
}

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL),cout.tie(NULL);
	
	cin>>n>>m;
	Max=-1e9,Min=1e9;
	for (int i=1; i<=n; i++)
		for (int j=1; j<=m; j++) {
			cin>>a[i][j];
			Max=max(Max,a[i][j]);
			Min=min(Min,a[i][j]);
		}
	
	ans=1e9;
	G();
	Rotate(); G();
	Rotate(); G();
	Rotate(); G();
	cout<<ans<<"\n";
}

Compilation message

joioi.cpp:44:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 8 ms 2304 KB Output is correct
17 Correct 13 ms 2560 KB Output is correct
18 Correct 11 ms 2560 KB Output is correct
19 Correct 13 ms 2560 KB Output is correct
20 Correct 12 ms 2432 KB Output is correct
21 Correct 13 ms 2688 KB Output is correct
22 Correct 14 ms 2816 KB Output is correct
23 Correct 16 ms 2688 KB Output is correct
24 Correct 13 ms 2560 KB Output is correct
25 Correct 17 ms 2688 KB Output is correct
26 Correct 15 ms 2560 KB Output is correct
27 Correct 14 ms 2688 KB Output is correct
28 Correct 15 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 512 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 512 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 1920 KB Output is correct
16 Correct 8 ms 2304 KB Output is correct
17 Correct 13 ms 2560 KB Output is correct
18 Correct 11 ms 2560 KB Output is correct
19 Correct 13 ms 2560 KB Output is correct
20 Correct 12 ms 2432 KB Output is correct
21 Correct 13 ms 2688 KB Output is correct
22 Correct 14 ms 2816 KB Output is correct
23 Correct 16 ms 2688 KB Output is correct
24 Correct 13 ms 2560 KB Output is correct
25 Correct 17 ms 2688 KB Output is correct
26 Correct 15 ms 2560 KB Output is correct
27 Correct 14 ms 2688 KB Output is correct
28 Correct 15 ms 2688 KB Output is correct
29 Correct 579 ms 53752 KB Output is correct
30 Correct 570 ms 53240 KB Output is correct
31 Correct 684 ms 54776 KB Output is correct
32 Correct 570 ms 54904 KB Output is correct
33 Correct 544 ms 51576 KB Output is correct
34 Correct 643 ms 54940 KB Output is correct
35 Correct 972 ms 70392 KB Output is correct
36 Correct 853 ms 65272 KB Output is correct
37 Correct 1054 ms 70648 KB Output is correct