답안 #365480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
365480 2021-02-11T17:40:43 Z tushar_2658 The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 364 KB
#include "bits/stdc++.h"
using namespace std;

const int maxn = 2005;
using ll = long long;

ll a[maxn][maxn], b[maxn][maxn];
int n, m;
ll mn = 1e9, mx = -1e9;

bool can(ll x){
  int MX = 0;
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= m; ++j){
      if(a[i][j] < mx - x){
        MX = max(MX, j);
      }
    }
    for(int j = 1; j <= MX; ++j){
      if(a[i][j] > mn + x){
        return 0;
      }
    }
  }
  return 1;
}

void rotate(){
  for(int i = 1; i <= n; ++i){
    for(int j = 1; j <= m; ++j){
      b[i][j] = a[i][j];
    }
  }
  for(int i = m; i > 0; --i){
    for(int j = 1; j <= n; ++j){
      a[i][j] = b[j][m - i + 1];
    }
  }
}

int main(int argc, char const *argv[])
{
  ios::sync_with_stdio(false); 
  cin.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(a[i][j], mn); 
      mx = max(a[i][j], mx);
    }
  }
  ll res = 1e9;
  for(int i = 1; i <= 4; ++i){
    ll lo = 0, hi = 1e9, ans = -1; 
    while(lo <= hi){
      ll mid = (lo + hi) >> 1; 
      if(can(mid)){
        ans = mid;
        hi = mid - 1;
      }else {
        lo = mid + 1;
      }
    }
    res = min(res, ans);
    rotate();
  }
  cout << res << '\n';
  
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -