답안 #533906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533906 2022-03-07T15:23:42 Z ioi The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 332 KB
#include<bits/stdc++.h>

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << endl;
#define inF freopen("6in.txt" , "r" , stdin);
#define outF freopen("6.txt" , "w" , stdout);
#define imod(a , n) (a % n + n ) % n
#define sor(v) sort(v.begin() , v.end());
#define print(v) for(auto f : v ) cout << f << " " ;
#define rsor(v) sort(v.rbegin() , v.rend());
#define rev(v) reverse(v.begin() , v.end());
#define scan(v)for(auto &it : v)cin >> it ;
#define ll long long
//#define int ll
#define logar(x , y) log(x) / log(y)
#define __sum(n) n * (n + 1) / 2
#define __lcm(a , b) a / __gcd(a , b) * b
#define pii pair<int , int >
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const int N =  2e3 + 5 ,  M = N * 64  , MX = 2e4 + 40;

int n , m ;

int arr[N][N];
int sz ;

bool check(int from , int to){
    int mx = 0 , mn = 1e9 , en = n;

    for(int c = 0 ; c < m ; c ++){
        for(int r = 0 ; r < n ; r ++){
            if(arr[r][c] < from || arr[r][c] > to)en = min(r , en) ;

            if(r >= en)mx = max(mx , arr[r][c] ) , mn = min(mn , arr[r][c]);
        }

    }


    return mx-mn <= to - from;

}

int arr2[N][N];
int32_t main()
{   //inF;
    //inF;outF;
    fastio;

    cin >> n >> m ;

    vector<int> v ;

    set<int> st ;

    int mx = 0 , mn = 1e9 ;

    for(int i = 0 ; i <  n; i ++){
        for(int j = 0 ; j <m; j ++){
            cin >> arr[i][j];
            arr2[i][j] =  arr[i][j];

            st.insert(arr[i][j]);
            mx = max(mx , arr[i][j]) , mn = min(mn , arr[i][j]);

        }
    }

    for(auto f : st)v.push_back(f);

    int sz = v.size();
    int mnans = mx - mn;
    for(int all = 0 ; all < 2 ; all ++){


        int  l = 0 , r = sz - 1 ,  md ;



        while(l <= r){


            md = (l + r) / 2 ;



            int d = v[md] - v[0];

            if(check(mn , mn + d) || check(mx - d , mx))
                mnans = min(mnans , d) ,  r = md- 1 ;
            else l = md + 1 ;


        }


        l = 0 , r = sz - 1 , md ;



         while(l <= r){


            md = (l + r) / 2 ;



            int d = v.back() - v[md];

            if(check(mn , mn + d) || check(mx - d , mx))
                mnans = min(mnans , d) ,  r = md- 1 ;
            else l = md + 1 ;


        }

        for(int c = 0 ; c < m ; c ++){
            for(int r = 0 ; r< n ; r ++){
                arr[r][c] = arr2[r][m - 1 - c];
               // debug(arr[r][c])
            }
        }
    }

    cout << mnans ;

}

Compilation message

joioi.cpp: In function 'int32_t main()':
joioi.cpp:98:33: warning: right operand of comma operator has no effect [-Wunused-value]
   98 |         l = 0 , r = sz - 1 , md ;
      |                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -