답안 #260248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260248 2020-08-09T21:55:11 Z Goolakh The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
1 ms 384 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 j=1;j<=m;j++)for(int i=1;i<=n/2;i++) swap(a[i][j],a[n-i+1][j]);
	}
	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;
}



 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Incorrect 1 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -