Submission #574079

# Submission time Handle Problem Language Result Execution time Memory
574079 2022-06-07T17:42:02 Z groshi The Kingdom of JOIOI (JOI17_joioi) C++17
100 / 100
460 ms 54844 KB
#include<iostream>

using namespace std;
int h,w;
int t[2010][2010];
int minn=1e9,maxx=0;
bool lewy_min(int sre)
{
    int lewo=w;
    for(int i=1;i<=h;i++)
    {
        for(int j=lewo;j>=1;j--)
            if(maxx-t[i][j]>sre)
                lewo=j-1;
        for(int j=lewo+1;j<=w;j++)
            if(t[i][j]-minn>sre)
                return 0;
    }
    return 1;
}
bool lewy_maxx(int sre)
{
    int lewo=w;
    for(int i=1;i<=h;i++)
    {
        for(int j=lewo;j>=1;j--)
            if(t[i][j]-minn>sre)
                lewo=j-1;
        for(int j=lewo+1;j<=w;j++)
            if(maxx-t[i][j]>sre)
                return 0;
    }
    return 1;
}
bool prawo_min(int sre)
{
    int prawo=w;
    for(int i=h;i>=1;i--)
    {
        for(int j=prawo;j>=1;j--)
            if(maxx-t[i][j]>sre)
                prawo=j-1;
        for(int j=prawo+1;j<=w;j++)
            if(t[i][j]-minn>sre)
                return 0;
    }
    return 1;
}
bool prawo_maxx(int sre)
{
    int prawo=w;
    for(int i=h;i>=1;i--)
    {
        for(int j=prawo;j>=1;j--)
            if(t[i][j]-minn>sre)
                prawo=j-1;
        for(int j=prawo+1;j<=w;j++)
            if(maxx-t[i][j]>sre)
                return 0;
    }
    return 1;
}
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    cin>>h>>w;
    for(int i=1;i<=h;i++)
    {
        for(int j=1;j<=w;j++)
        {
            cin>>t[i][j];
            maxx=max(maxx,t[i][j]);
            minn=min(minn,t[i][j]);
        }
    }
    int pocz=0,kon=1e9+1,sre,ostd=0;
    while(pocz<kon)
    {
        sre=(pocz+kon)/2;
        if(lewy_min(sre) || lewy_maxx(sre) || prawo_min(sre) || prawo_maxx(sre))
        {
            kon=sre;
            ostd=sre;
        }
        else pocz=sre+1;
    }
    cout<<ostd;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1288 KB Output is correct
17 Correct 5 ms 1492 KB Output is correct
18 Correct 5 ms 1512 KB Output is correct
19 Correct 5 ms 1620 KB Output is correct
20 Correct 5 ms 1368 KB Output is correct
21 Correct 6 ms 1608 KB Output is correct
22 Correct 5 ms 1628 KB Output is correct
23 Correct 5 ms 1620 KB Output is correct
24 Correct 5 ms 1496 KB Output is correct
25 Correct 5 ms 1624 KB Output is correct
26 Correct 5 ms 1612 KB Output is correct
27 Correct 6 ms 1644 KB Output is correct
28 Correct 6 ms 1620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 336 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 4 ms 1288 KB Output is correct
17 Correct 5 ms 1492 KB Output is correct
18 Correct 5 ms 1512 KB Output is correct
19 Correct 5 ms 1620 KB Output is correct
20 Correct 5 ms 1368 KB Output is correct
21 Correct 6 ms 1608 KB Output is correct
22 Correct 5 ms 1628 KB Output is correct
23 Correct 5 ms 1620 KB Output is correct
24 Correct 5 ms 1496 KB Output is correct
25 Correct 5 ms 1624 KB Output is correct
26 Correct 5 ms 1612 KB Output is correct
27 Correct 6 ms 1644 KB Output is correct
28 Correct 6 ms 1620 KB Output is correct
29 Correct 337 ms 37308 KB Output is correct
30 Correct 329 ms 37488 KB Output is correct
31 Correct 380 ms 39184 KB Output is correct
32 Correct 343 ms 39148 KB Output is correct
33 Correct 309 ms 34240 KB Output is correct
34 Correct 388 ms 39176 KB Output is correct
35 Correct 452 ms 54804 KB Output is correct
36 Correct 427 ms 49628 KB Output is correct
37 Correct 460 ms 54844 KB Output is correct