답안 #1116513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116513 2024-11-21T18:36:31 Z staszic_ojuz The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
1 ms 336 KB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> m;
int inf = 2000000000;
int mini = 2000000000;
int h,w;
bool check(int x)
{
    int jl = w;
    int max2 = 0,min2 = inf;
    for(int i = 0; i<h; i++)
    {
        for(int j = 0; j<w; j++)
        {
            if(m[i][j] > x+mini)
            {
                jl = j;
            }
            if(j >= jl)
            {
                max2 = max(max2,m[i][j]);
                min2 = min(min2,m[i][j]);
            }
        }
    }
    //cout<<max2<<" "<<min2<<" "<<jl<<"\n";
    if(max2 - min2 <= x)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int bs()
{
    int l = 0;
    int r = 1e9;
    while(l < r)
    {
        int mid = (l+r)/2;
        if(check(mid))
        {
            r = mid-1;
        }
        else
        {
            l = mid+1;
        }
        //cout<<mid<<"\n";
    }
    return l+1;
}
int main()
{
    cin>>h>>w;
    m.resize(h);
    for(int i = 0; i<h; i++)
    {
        for(int j = 0; j<w; j++)
        {
            int x;
            cin>>x;
            m[i].push_back(x);
            mini = min(mini,x);
        }
    }
    int ans = bs();
    //cout<<ans<<"\n"<<"\n";
    reverse(m.begin(),m.end());
    ans = min(ans,bs());
    //cout<<ans<<"\n"<<"\n";r
    for(int i = 0; i<h; i++)
    {
        reverse(m[i].begin(),m[i].end());
    }
    ans = min(ans,bs());
    //cout<<ans<<"\n"<<"\n";
    reverse(m.begin(),m.end());
    ans = min(ans,bs());
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -