Submission #396792

# Submission time Handle Problem Language Result Execution time Memory
396792 2021-04-30T18:38:28 Z keta_tsimakuridze The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
4000 ms 177056 KB
#include<bits/stdc++.h>
#define f first
#define s second
using namespace std;
const int N=2e3+5,mod=1e9+7;
int t,a[N][N],r[N],l[N],mn[N],mx[N],n,m,ans,mid;
map<int,int> fix;
vector<int> val;
string s;

bool check(int mx1){
	int diff=mx1-val[0];
	for(int i=1;i<=n;i++) {
		l[i]=m+1;  r[i]=0;
	}
	for(int i=1;i<=n;i++) {
		for(int j=m;j>=1;j--){
			if(a[i][j]>mx1) l[i] = j - 1;
		}
		for(int j=1;j<=m;j++){
			if(a[i][j]+diff<val.back()) r[i] = j ;
		}
		 // [r[i] , l[i]) 
		 if(l[i]<r[i]) return 0;
	}
	int F=0;
	int cur=m;
	for(int i=1;i<=n;i++) {
		if(r[i]>cur) {
			F=1;
			break;
		} 
		cur = min(l[i],cur);
	}
	if(!F) return 1; 
	F=0;
	cur=0;
	for(int i=1;i<=n;i++) {
		if(l[i]<cur) {
			F=1;
			break;
		}
		cur = max(r[i],cur);
	}
	if(!F) return 1;
	return 0;
}
void search(){	
	int l = 0,r =1e9+9;
	while(l<=r){
		 mid=(l+r)/2; 
		if(check(mid)) { 
			ans =min(ans, (mid-val[0])); 
			r=mid-1;
		}
		else l=mid+1;
	}
}
 main(){
 	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	// t=1;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin >> a[i][j]; 
			if(!fix[a[i][j]]) val.push_back(a[i][j]);
			fix[a[i][j]]=1;
		}
		
	} 
	sort(val.begin(),val.end()); ans=val.back()-val[0];
	search();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m/2;j++){
			swap(a[i][j],a[i][m-j+1]);
		}
	}
	search();
	val.clear();
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=m;j++){
			a[i][j]=-a[i][j];
			if(!fix[a[i][j]]) val.push_back(a[i][j]);
			fix[a[i][j]]=1;
		}
	}
	cout<<ans;
}

Compilation message

joioi.cpp:59:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   59 |  main(){
      |       ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 10 ms 1228 KB Output is correct
17 Correct 56 ms 5056 KB Output is correct
18 Correct 44 ms 5032 KB Output is correct
19 Correct 46 ms 5056 KB Output is correct
20 Correct 41 ms 4544 KB Output is correct
21 Correct 48 ms 5132 KB Output is correct
22 Correct 47 ms 5092 KB Output is correct
23 Correct 54 ms 5124 KB Output is correct
24 Correct 37 ms 4556 KB Output is correct
25 Correct 49 ms 5220 KB Output is correct
26 Correct 47 ms 5112 KB Output is correct
27 Correct 45 ms 5128 KB Output is correct
28 Correct 47 ms 5152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 444 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 10 ms 1228 KB Output is correct
17 Correct 56 ms 5056 KB Output is correct
18 Correct 44 ms 5032 KB Output is correct
19 Correct 46 ms 5056 KB Output is correct
20 Correct 41 ms 4544 KB Output is correct
21 Correct 48 ms 5132 KB Output is correct
22 Correct 47 ms 5092 KB Output is correct
23 Correct 54 ms 5124 KB Output is correct
24 Correct 37 ms 4556 KB Output is correct
25 Correct 49 ms 5220 KB Output is correct
26 Correct 47 ms 5112 KB Output is correct
27 Correct 45 ms 5128 KB Output is correct
28 Correct 47 ms 5152 KB Output is correct
29 Correct 3676 ms 25084 KB Output is correct
30 Correct 3732 ms 25728 KB Output is correct
31 Correct 3885 ms 25728 KB Output is correct
32 Correct 3786 ms 48884 KB Output is correct
33 Correct 3040 ms 42528 KB Output is correct
34 Correct 3700 ms 48972 KB Output is correct
35 Execution timed out 4085 ms 177056 KB Time limit exceeded
36 Halted 0 ms 0 KB -