Submission #225368

# Submission time Handle Problem Language Result Execution time Memory
225368 2020-04-20T12:06:32 Z MKopchev The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1069 ms 55416 KB
#include<bits/stdc++.h>
using namespace std;
const int nmax=2e3+42;

int n,m;

int inp[nmax][nmax];

int mini,maxi;

int output;

bool can(int cur)
{
    int j_line=0;

    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
            if(inp[i][j]-mini>cur)j_line=max(j_line,j);

        for(int j=1;j<=j_line;j++)
            if(maxi-inp[i][j]>cur)return 0;

        for(int j=j_line+1;j<=m;j++)
            if(inp[i][j]-mini>cur)return 0;
    }
    return 1;
}
void solve()
{
    int ok=output,not_ok=-1;
    while(ok-not_ok>1)
    {
        int av=(ok+not_ok)/2;
        if(can(av))ok=av;
        else not_ok=av;
    }
    output=ok;
}

void rotate_1()
{
    for(int i=1;i<n+1-i;i++)
        for(int j=1;j<=m;j++)
            swap(inp[i][j],inp[n+1-i][j]);
}

void rotate_2()
{
    for(int i=1;i<=n;i++)
        for(int j=1;j<m+1-j;j++)
            swap(inp[i][j],inp[i][m+1-j]);
}

int main()
{
    scanf("%i%i",&n,&m);

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
            scanf("%i",&inp[i][j]);

    mini=inp[1][1];
    maxi=inp[1][1];

    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
        {
            mini=min(mini,inp[i][j]);
            maxi=max(maxi,inp[i][j]);
        }

    output=maxi-mini;

    solve();

    rotate_1();
    solve();

    rotate_2();
    solve();

    rotate_1();
    solve();

    printf("%i\n",output);
    return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%i%i",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
joioi.cpp:62:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%i",&inp[i][j]);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1408 KB Output is correct
17 Correct 13 ms 1536 KB Output is correct
18 Correct 13 ms 1536 KB Output is correct
19 Correct 14 ms 1536 KB Output is correct
20 Correct 16 ms 1408 KB Output is correct
21 Correct 16 ms 1664 KB Output is correct
22 Correct 14 ms 1664 KB Output is correct
23 Correct 22 ms 1664 KB Output is correct
24 Correct 15 ms 1536 KB Output is correct
25 Correct 17 ms 1664 KB Output is correct
26 Correct 16 ms 1664 KB Output is correct
27 Correct 18 ms 1664 KB Output is correct
28 Correct 23 ms 1792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 6 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1408 KB Output is correct
17 Correct 13 ms 1536 KB Output is correct
18 Correct 13 ms 1536 KB Output is correct
19 Correct 14 ms 1536 KB Output is correct
20 Correct 16 ms 1408 KB Output is correct
21 Correct 16 ms 1664 KB Output is correct
22 Correct 14 ms 1664 KB Output is correct
23 Correct 22 ms 1664 KB Output is correct
24 Correct 15 ms 1536 KB Output is correct
25 Correct 17 ms 1664 KB Output is correct
26 Correct 16 ms 1664 KB Output is correct
27 Correct 18 ms 1664 KB Output is correct
28 Correct 23 ms 1792 KB Output is correct
29 Correct 621 ms 37624 KB Output is correct
30 Correct 638 ms 38008 KB Output is correct
31 Correct 721 ms 39676 KB Output is correct
32 Correct 647 ms 39592 KB Output is correct
33 Correct 553 ms 34424 KB Output is correct
34 Correct 690 ms 39760 KB Output is correct
35 Correct 954 ms 55220 KB Output is correct
36 Correct 745 ms 49928 KB Output is correct
37 Correct 1069 ms 55416 KB Output is correct