Submission #533902

# Submission time Handle Problem Language Result Execution time Memory
533902 2022-03-07T15:06:21 Z ioi The Kingdom of JOIOI (JOI17_joioi) C++14
60 / 100
4000 ms 35820 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 ;

    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];


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

        }
    }


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


        int  l = 0 , r = mx - mn , md ;



        while(l <= r){


            md = (l + r) / 2 ;


            if(check(mn , mn + md) || check(mx - md , mx))
                mnans = min(mnans , md) ,  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 ;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 2128 KB Output is correct
17 Correct 11 ms 2204 KB Output is correct
18 Correct 10 ms 2124 KB Output is correct
19 Correct 12 ms 2252 KB Output is correct
20 Correct 10 ms 2028 KB Output is correct
21 Correct 13 ms 2124 KB Output is correct
22 Correct 14 ms 2124 KB Output is correct
23 Correct 14 ms 2252 KB Output is correct
24 Correct 16 ms 1984 KB Output is correct
25 Correct 15 ms 2124 KB Output is correct
26 Correct 16 ms 2252 KB Output is correct
27 Correct 13 ms 2124 KB Output is correct
28 Correct 14 ms 2244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 5 ms 2128 KB Output is correct
17 Correct 11 ms 2204 KB Output is correct
18 Correct 10 ms 2124 KB Output is correct
19 Correct 12 ms 2252 KB Output is correct
20 Correct 10 ms 2028 KB Output is correct
21 Correct 13 ms 2124 KB Output is correct
22 Correct 14 ms 2124 KB Output is correct
23 Correct 14 ms 2252 KB Output is correct
24 Correct 16 ms 1984 KB Output is correct
25 Correct 15 ms 2124 KB Output is correct
26 Correct 16 ms 2252 KB Output is correct
27 Correct 13 ms 2124 KB Output is correct
28 Correct 14 ms 2244 KB Output is correct
29 Correct 2085 ms 30128 KB Output is correct
30 Correct 2212 ms 31696 KB Output is correct
31 Correct 2553 ms 31684 KB Output is correct
32 Correct 2362 ms 31712 KB Output is correct
33 Correct 1898 ms 27904 KB Output is correct
34 Correct 2516 ms 31692 KB Output is correct
35 Execution timed out 4032 ms 35820 KB Time limit exceeded
36 Halted 0 ms 0 KB -