답안 #1114088

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114088 2024-11-18T07:39:57 Z Dan4Life Snowball (JOI21_ho_t2) C++17
0 / 100
1 ms 2384 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
const int N = (int)2e3+10;
bitset<N> dp[N];
int n, m, a[N][N], b[N][N], c[N][N];
 
void Rotate(){
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			c[i][j] = b[i][j];
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			b[j][i] = c[i][m-j-1];
	swap(n,m);
}
 
bool calc(){
	int bst=-1,bst2,lst,sum;
	for(int i = 0; i < n; i++){
		bst2=-1; lst=0; sum = 0;
		for(int j = m-1; j>=0; j--){
			if(b[i][j]==1){ lst=j+1; break; }
		}
		for(int j = 0; j < lst; j++) 
			dp[i][j]=0, sum+=(b[i][j]<=1);
		for(int j = lst; j <= m; j++){
			if(sum!=j){
				for(int k = j; k <= m; k++)dp[i][k]=0;
				break;
			}
			if(!i) dp[i][j]=(j!=m);
			else if(bst!=-1) dp[i][j]=(bst<=j);
			else dp[i][j]=0;
			if(dp[i][j] and bst2==-1) bst2=j; 
			sum+=(b[i][j]<=1);
		}
		bst=bst2;
	}
	bool ok = 0;
	for(int i = 1; i <= m; i++) ok|=dp[n-1][i];
	return ok;
}
 
int mn = (int)1e9, mx = 0;
bool chk(int R){
	memset(b,0,sizeof(b));
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			if(a[i][j]>mn+R) b[i][j]=2;
			if(a[i][j]<mx-R){
				if(b[i][j]==2) return 0;
				b[i][j] = 1;
			}
		}
	}
	bool ok = 0;
	for(int i = 0; i < 4; i++) 
		ok|=calc(), Rotate();
	return ok;
}
 
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	for(int i = 0; i < n; i++)
		for(int j = 0; j < m; j++)
			cin >> a[i][j],mn=min(mn,a[i][j]),mx=max(mx,a[i][j]);
	int l = 0, r = mx-mn;
	while(l<r){
		int mid = (l+r)/2;
		if(chk(mid)) r=mid;
		else l=mid+1;
	}
	cout << l << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2384 KB Output isn't correct
2 Halted 0 ms 0 KB -