Submission #260260

# Submission time Handle Problem Language Result Execution time Memory
260260 2020-08-09T22:11:54 Z Goolakh The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1137 ms 74760 KB
// FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=2e3+10, maxm=1e6+10, lg=15, mod=1e9+7, inf=1e18;

ll n,m,a[maxn][maxn],mn=inf,mx=0;
bool ps[maxn][maxn];
bool check(ll d){
	for(int tt=0;tt<2;tt++){
		for(int i=1;i<=n;i++){
			for(int j=0;j<=m;j++) ps[i][j]=0;
			ll l=1,r=m;
			for(;l<=m;l++)if(a[i][l]>mn+d) break;
			for(;r>=1;r--)if(a[i][r]<mx-d) break;
			bool ok=0;
			for(int j=0;j<l;j++){
				ok|=ps[i-1][j];
				if(ok && r<=j) ps[i][j]=1;
			}
		}
		for(int j=0;j<=m;j++)if(ps[n][j]) return 1;
		for(int i=1;i<=n;i++){
			for(int j=0;j<=m;j++) ps[i][j]=0;
			ll l=1,r=m;
			for(;l<=m;l++)if(a[i][l]<mx-d) break;
			for(;r>=1;r--)if(a[i][r]>mn+d) break;
			bool ok=0;
			for(int j=0;j<l;j++){
				ok|=ps[i-1][j];
				if(ok && r<=j) ps[i][j]=1;
			}
		}
		for(int j=0;j<=m;j++)if(ps[n][j]) return 1;
		for(int i=1;i<=n;i++)for(int j=1;j<=m/2;j++) swap(a[i][j],a[i][m-j+1]);
	}
	return 0;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>m;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) cin>>a[i][j], mn=min(mn,a[i][j]), mx=max(mx,a[i][j]);
	for(int i=0;i<=m;i++) ps[0][i]=1;
	ll l=0,r=mod,mid;
	while(r-l>1){
		mid=(l+r)/2;
		if(check(mid)) r=mid;
		else l=mid;
	}
	cout<<r;
	
	return 0;
}



 
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1920 KB Output is correct
17 Correct 14 ms 2176 KB Output is correct
18 Correct 10 ms 2176 KB Output is correct
19 Correct 10 ms 2176 KB Output is correct
20 Correct 9 ms 1920 KB Output is correct
21 Correct 16 ms 2560 KB Output is correct
22 Correct 12 ms 2304 KB Output is correct
23 Correct 11 ms 2304 KB Output is correct
24 Correct 13 ms 2048 KB Output is correct
25 Correct 12 ms 2304 KB Output is correct
26 Correct 13 ms 2304 KB Output is correct
27 Correct 16 ms 2304 KB Output is correct
28 Correct 17 ms 2304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1920 KB Output is correct
17 Correct 14 ms 2176 KB Output is correct
18 Correct 10 ms 2176 KB Output is correct
19 Correct 10 ms 2176 KB Output is correct
20 Correct 9 ms 1920 KB Output is correct
21 Correct 16 ms 2560 KB Output is correct
22 Correct 12 ms 2304 KB Output is correct
23 Correct 11 ms 2304 KB Output is correct
24 Correct 13 ms 2048 KB Output is correct
25 Correct 12 ms 2304 KB Output is correct
26 Correct 13 ms 2304 KB Output is correct
27 Correct 16 ms 2304 KB Output is correct
28 Correct 17 ms 2304 KB Output is correct
29 Correct 879 ms 56136 KB Output is correct
30 Correct 812 ms 57336 KB Output is correct
31 Correct 848 ms 59000 KB Output is correct
32 Correct 839 ms 59000 KB Output is correct
33 Correct 768 ms 51448 KB Output is correct
34 Correct 822 ms 59000 KB Output is correct
35 Correct 1137 ms 74616 KB Output is correct
36 Correct 1049 ms 69236 KB Output is correct
37 Correct 1098 ms 74760 KB Output is correct