답안 #167920

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
167920 2019-12-10T19:26:23 Z theStaticMind The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
2 ms 376 KB
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int n,m;
int mx=-INF,mn=INF;
bool solve(vector<vector<int>>&arr,int x,int y){
      int Y=m;
      vector<int> lim(n,0);
      for(int i=0;i<n;i++){
            for(int j=0;j<Y;j++){
                  if(arr[i][j]>x)Y=j;
            }
            lim[i]=Y;
      }
      for(int i=n-1;i>=0;i--){
            for(int j=m-1;j>=lim[i];j--){
                  if(arr[i][j]<y)return false;
            }
      }
      return true;
}
int binary_search(vector<vector<int>>& arr){
      int l=0,r=mx-mn,ans=INF;
      while(l<r){
            int mid=(l+r)/2;
            if(solve(arr,mn+mid,mx-mid)){
                  ans=min(ans,mid);
                  r=mid-1;
            }
            else l=mid+1;
      }
      return ans;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      cin>>n>>m;
      vector<vector<int>>arr(n,vector<int>(m));
      for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                  cin>>arr[i][j];
                  int x=arr[i][j];
                  mn=min(mn,x);
                  mx=max(mx,x);
            }
      }
      int ans=INF;
      ans=min(ans,binary_search(arr));
      reverse(all(arr));
      ans=min(ans,binary_search(arr));
      for(int i=0;i<n;i++)reverse(all(arr[i]));
      ans=min(ans,binary_search(arr));
      reverse(all(arr));
      ans=min(ans,binary_search(arr));
      cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -