Submission #228000

# Submission time Handle Problem Language Result Execution time Memory
228000 2020-04-29T13:34:25 Z dvdg6566 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
3172 ms 81052 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
const ll MAXN = 2010;
const ll INF = 1e18;
const ll MOD = 1e9+7;

ll N,M;
ll A[MAXN][MAXN];
ll LOW, UPP;
int B[MAXN][MAXN];
pi ones[MAXN], twos[MAXN];

bool ask(){
	ll L=0;
	// for (int i=1;i<=N;++i){for(int j=1;j<=M;++j)cout<<B[i][j]<<' ';cout<<'\n';}
	for(int i=1;i<=N;++i){
		ones[i]=mp(INF,0);
		twos[i]=mp(INF,0);
		for(ll j=1;j<=M;++j){
			if(B[i][j]==1){
				ones[i].f=min(ones[i].f,j);
				ones[i].s=max(ones[i].s,j);
			}else if(B[i][j]==2){
				twos[i].f=min(twos[i].f,j);
				twos[i].s=max(twos[i].s,j);
			}
		}
		if(ones[i].f!=INF){
			L=max(L,ones[i].s);
		}
		if (twos[i].f!=INF&&twos[i].f<=L)return 0;
		// cout<<ones[i].f<<' '<<ones[i].s<<'\n';
		// cout<<twos[i].f<<' '<<twos[i].s<<'\n';
	}
	return 1;
}

bool works(int L){
	pi a = mp(LOW,LOW+L);
	pi b = mp(UPP-L,UPP);
	for(int i=1;i<=N;++i)for(int j=1;j<=M;++j){
		if(A[i][j]<b.f&&A[i][j]>a.s)return 0;
		if(A[i][j]<b.f)B[i][j]=1;
		else if(A[i][j]>a.s)B[i][j]=2;
		else B[i][j]=0;
	}
	for(int rep=0;rep<4;++rep){
		int t=ask();
		if(t)return 1;
		if (rep==0||rep==2){
			// flip hori
			for (int i=1;i<=N;++i)for (int j=1;j+j<=M;++j){
				swap(B[i][j], B[i][M+1-j]);
			}
		}else{
			for (int i=1;i+i<=N;++i)for(int j=1;j<=M;++j){
				swap(B[i][j], B[N+1-i][j]);
			}
		}
		// break;
	}
	return 0;
}

int main(){
	cin>>N>>M;
	LOW=INF;
	for (int i=1;i<=N;++i)for(int j=1;j<=M;++j){
		cin>>A[i][j];
		UPP=max(UPP,A[i][j]);
		LOW=min(LOW,A[i][j]);
	}
	
	ll lb=0;
	ll ub=UPP-LOW+1;
	while(ub>lb){
		int mid=(lb+ub)/2;
		// cerr<<mid<<'\n';
		if(works(mid))ub=mid;
		else lb=mid+1;
	}
	cout<<lb;
}
# 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 384 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 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 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 384 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 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 13 ms 2560 KB Output is correct
17 Correct 26 ms 2688 KB Output is correct
18 Correct 25 ms 2688 KB Output is correct
19 Correct 28 ms 2688 KB Output is correct
20 Correct 25 ms 2432 KB Output is correct
21 Correct 34 ms 2808 KB Output is correct
22 Correct 32 ms 2808 KB Output is correct
23 Correct 38 ms 2808 KB Output is correct
24 Correct 29 ms 2552 KB Output is correct
25 Correct 41 ms 2816 KB Output is correct
26 Correct 35 ms 2936 KB Output is correct
27 Correct 35 ms 2816 KB Output is correct
28 Correct 34 ms 2808 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 384 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 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 512 KB Output is correct
15 Correct 5 ms 512 KB Output is correct
16 Correct 13 ms 2560 KB Output is correct
17 Correct 26 ms 2688 KB Output is correct
18 Correct 25 ms 2688 KB Output is correct
19 Correct 28 ms 2688 KB Output is correct
20 Correct 25 ms 2432 KB Output is correct
21 Correct 34 ms 2808 KB Output is correct
22 Correct 32 ms 2808 KB Output is correct
23 Correct 38 ms 2808 KB Output is correct
24 Correct 29 ms 2552 KB Output is correct
25 Correct 41 ms 2816 KB Output is correct
26 Correct 35 ms 2936 KB Output is correct
27 Correct 35 ms 2816 KB Output is correct
28 Correct 34 ms 2808 KB Output is correct
29 Correct 1879 ms 67448 KB Output is correct
30 Correct 1888 ms 69240 KB Output is correct
31 Correct 2105 ms 63992 KB Output is correct
32 Correct 1883 ms 64856 KB Output is correct
33 Correct 1605 ms 61840 KB Output is correct
34 Correct 2037 ms 62040 KB Output is correct
35 Correct 2798 ms 69876 KB Output is correct
36 Correct 2454 ms 81052 KB Output is correct
37 Correct 3172 ms 69748 KB Output is correct