답안 #946212

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
946212 2024-03-14T12:14:27 Z Xiaoyang The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1593 ms 111308 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define fi first 
#define se second 
#define pll pair<ll,ll>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl;
#define MP make_pair
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define SZ(x) (ll)x.size()
#define ALL(x) x.begin(),x.end()
#define endl "\n"
const ll inf=1e18;
ll lowbit(ll x){return x&(-x);}


const ll maxn=2222;
ll grid[maxn][maxn];
ll tmp[maxn][maxn];
ll n,m;
ll MIN=inf;
void rot(){
	rep(i,1,n+1){
		rep(j,1,m+1){
			tmp[j][n+1-i]=grid[i][j];
		}
	}
	swap(n,m);
	rep(i,1,n+1){
		rep(j,1,m+1){
			grid[i][j]=tmp[i][j];
		}
	}
}

bool check(ll mid){
	rep(r,0,4){
		ll lst=m,mx=0,mn=inf;
		rep(i,1,n+1){
			rep(j,1,lst+1){
				if(grid[i][j]>MIN+mid){
					lst=j-1;
					break;
				}
			}
			//the section above is always valid
			//below we just take max and min of that section and check 
			rep(j,lst+1,m+1){
				mx=max(mx,grid[i][j]);
				mn=min(mn,grid[i][j]);
			}
		}
		if(mx-mn<=mid)return 1;
		rot();
	}
	return 0;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m;
	rep(i,1,n+1){
		rep(j,1,m+1){
			cin>>grid[i][j];
			MIN=min(MIN,grid[i][j]);
		}
	}
	
	ll lo=0,hi=1e9;
	while(lo<hi){
		ll mid=(lo+hi)>>1;
		if(check(mid))hi=mid;
		else lo=mid+1;
	}
	cout<<lo<<endl;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2484 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2484 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 4 ms 10788 KB Output is correct
17 Correct 7 ms 10844 KB Output is correct
18 Correct 8 ms 10888 KB Output is correct
19 Correct 8 ms 11048 KB Output is correct
20 Correct 8 ms 10912 KB Output is correct
21 Correct 11 ms 11104 KB Output is correct
22 Correct 13 ms 11348 KB Output is correct
23 Correct 9 ms 11104 KB Output is correct
24 Correct 9 ms 11104 KB Output is correct
25 Correct 10 ms 11084 KB Output is correct
26 Correct 10 ms 11100 KB Output is correct
27 Correct 10 ms 11100 KB Output is correct
28 Correct 13 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2392 KB Output is correct
3 Correct 1 ms 2392 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2512 KB Output is correct
12 Correct 1 ms 2484 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 2 ms 10588 KB Output is correct
16 Correct 4 ms 10788 KB Output is correct
17 Correct 7 ms 10844 KB Output is correct
18 Correct 8 ms 10888 KB Output is correct
19 Correct 8 ms 11048 KB Output is correct
20 Correct 8 ms 10912 KB Output is correct
21 Correct 11 ms 11104 KB Output is correct
22 Correct 13 ms 11348 KB Output is correct
23 Correct 9 ms 11104 KB Output is correct
24 Correct 9 ms 11104 KB Output is correct
25 Correct 10 ms 11084 KB Output is correct
26 Correct 10 ms 11100 KB Output is correct
27 Correct 10 ms 11100 KB Output is correct
28 Correct 13 ms 11096 KB Output is correct
29 Correct 1098 ms 94748 KB Output is correct
30 Correct 937 ms 94024 KB Output is correct
31 Correct 999 ms 95708 KB Output is correct
32 Correct 1108 ms 95572 KB Output is correct
33 Correct 891 ms 92564 KB Output is correct
34 Correct 1125 ms 95640 KB Output is correct
35 Correct 1593 ms 111196 KB Output is correct
36 Correct 1415 ms 106148 KB Output is correct
37 Correct 1550 ms 111308 KB Output is correct