답안 #339173

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
339173 2020-12-24T18:32:25 Z Atill83 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
974 ms 70840 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 2e3+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll h, w;
int mx = 0, mn = mod;
int g[MAXN][MAXN], ot[MAXN][MAXN];
inline void turn(){
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            ot[j][h - 1 - i] = g[i][j];

    swap(h, w);
    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++)
            g[i][j] = ot[i][j];
}

inline bool check(int del){
    int sn = 0;
    for(int i = 0; i < h; i++){

        for(int j = 0; j < w; j++){
            if(g[i][j] < mx - del)
                sn = max(sn, j + 1);
        }
    
        for(int j = 0; j < sn; j++){
            if(g[i][j] > mn + del)
                return 0;
        }
        
    }
    return 1;
}




int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>h>>w;

    for(int i = 0; i < h; i++)
        for(int j = 0; j < w; j++){
            cin>>g[i][j];
            mx = max(mx, g[i][j]);
            mn = min(mn, g[i][j]);
        }


    int ans = mod;
    int cn = 0;
    do{
        int l = 0, r = (int) 1e9;
        while(l < r){
            int m = (l + r) / 2;
            if(check(m))
                r = m;
            else
                l = m + 1;
        }
        
        ans = min(ans, l);
        turn();
    } while(++cn < 4);
    cout<<ans<<endl;
    

    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 8 ms 2284 KB Output is correct
17 Correct 13 ms 2284 KB Output is correct
18 Correct 10 ms 2284 KB Output is correct
19 Correct 10 ms 2284 KB Output is correct
20 Correct 9 ms 2284 KB Output is correct
21 Correct 9 ms 2284 KB Output is correct
22 Correct 9 ms 2284 KB Output is correct
23 Correct 10 ms 2284 KB Output is correct
24 Correct 9 ms 2284 KB Output is correct
25 Correct 11 ms 2284 KB Output is correct
26 Correct 10 ms 2284 KB Output is correct
27 Correct 9 ms 2284 KB Output is correct
28 Correct 9 ms 2156 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 512 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 2 ms 2028 KB Output is correct
16 Correct 8 ms 2284 KB Output is correct
17 Correct 13 ms 2284 KB Output is correct
18 Correct 10 ms 2284 KB Output is correct
19 Correct 10 ms 2284 KB Output is correct
20 Correct 9 ms 2284 KB Output is correct
21 Correct 9 ms 2284 KB Output is correct
22 Correct 9 ms 2284 KB Output is correct
23 Correct 10 ms 2284 KB Output is correct
24 Correct 9 ms 2284 KB Output is correct
25 Correct 11 ms 2284 KB Output is correct
26 Correct 10 ms 2284 KB Output is correct
27 Correct 9 ms 2284 KB Output is correct
28 Correct 9 ms 2156 KB Output is correct
29 Correct 872 ms 31724 KB Output is correct
30 Correct 876 ms 53272 KB Output is correct
31 Correct 974 ms 55144 KB Output is correct
32 Correct 877 ms 55084 KB Output is correct
33 Correct 776 ms 51692 KB Output is correct
34 Correct 895 ms 55148 KB Output is correct
35 Correct 866 ms 70636 KB Output is correct
36 Correct 750 ms 65484 KB Output is correct
37 Correct 933 ms 70840 KB Output is correct