Submission #365474

# Submission time Handle Problem Language Result Execution time Memory
365474 2021-02-11T17:37:04 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){
  for(int i = 1; i <= n; ++i){
    int MX = 0;
    for(int j = 1; j <= m; ++j){
      if(a[i][j] > mn + x){
        MX = j;
      }
    }
    for(int j = 1; j < MX; ++j){
      if(a[i][j] < mx - 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -