답안 #1116542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1116542 2024-11-21T19:39:04 Z staszic_ojuz The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
1024 ms 55232 KB
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> m;
int inf = 2000000000;
int mini = inf;
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 = min(j,jl);
            }
            if(j >= jl)
            {
                max2 = max(max2,m[i][j]);
                min2 = min(min2,m[i][j]);
            }
        }
    }
    if(max2 - min2 <= x)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int bs()
{
    int l = -1;
    int r = 1e9;
    while(l+1 < r)
    {
        int mid = (l+r)/2;
        if(check(mid))
        {
            r = mid;
        }
        else
        {
            l = mid;
        }
    }
    return r;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    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();
    reverse(m.begin(),m.end());
    ans = min(ans,bs());
    for(int i = 0; i<h; i++)
    {
        reverse(m[i].begin(),m[i].end());
    }
    ans = min(ans,bs());
    reverse(m.begin(),m.end());
    ans = min(ans,bs());
    cout<<ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 8 ms 764 KB Output is correct
17 Correct 8 ms 728 KB Output is correct
18 Correct 9 ms 848 KB Output is correct
19 Correct 9 ms 848 KB Output is correct
20 Correct 10 ms 884 KB Output is correct
21 Correct 10 ms 848 KB Output is correct
22 Correct 10 ms 844 KB Output is correct
23 Correct 10 ms 848 KB Output is correct
24 Correct 11 ms 1020 KB Output is correct
25 Correct 11 ms 848 KB Output is correct
26 Correct 11 ms 848 KB Output is correct
27 Correct 10 ms 848 KB Output is correct
28 Correct 11 ms 848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 8 ms 764 KB Output is correct
17 Correct 8 ms 728 KB Output is correct
18 Correct 9 ms 848 KB Output is correct
19 Correct 9 ms 848 KB Output is correct
20 Correct 10 ms 884 KB Output is correct
21 Correct 10 ms 848 KB Output is correct
22 Correct 10 ms 844 KB Output is correct
23 Correct 10 ms 848 KB Output is correct
24 Correct 11 ms 1020 KB Output is correct
25 Correct 11 ms 848 KB Output is correct
26 Correct 11 ms 848 KB Output is correct
27 Correct 10 ms 848 KB Output is correct
28 Correct 11 ms 848 KB Output is correct
29 Correct 831 ms 37732 KB Output is correct
30 Correct 820 ms 38216 KB Output is correct
31 Correct 826 ms 39652 KB Output is correct
32 Correct 758 ms 39372 KB Output is correct
33 Correct 632 ms 34476 KB Output is correct
34 Correct 948 ms 37564 KB Output is correct
35 Correct 908 ms 55232 KB Output is correct
36 Correct 761 ms 50060 KB Output is correct
37 Correct 1024 ms 54932 KB Output is correct