Submission #978818

# Submission time Handle Problem Language Result Execution time Memory
978818 2024-05-09T17:54:29 Z vjudge1 The Kingdom of JOIOI (JOI17_joioi) C
100 / 100
1319 ms 78932 KB
#include<stdio.h>

#define N 2000
#define M 2000

int max(int i,int j){return i<j?j:i;}
int min(int i,int j){return i>j?j:i;}

int n, m, a[N][M], b[N][M], c[N][M], d[N][M], x, ii, jj;

int ok_(int a[][M], int ii, int jj)
{
    static int down[M][N];
    for(int i=0;i<m;++i)
    {
        down[i][0]=a[0][i];
        for(int j=1;j<n;++j)
            down[i][j]=min(down[i][j-1],a[j][i]);
    }

    int high = a[ii][jj];

    static int sep[M];
    int ptr=n-1;
    for(int i=0;i<m;++i)
    {
        while(ptr>=0&&down[i][ptr]+x<high)--ptr;
        sep[i]=ptr+1;
        if(jj == i && sep[i] <= ii)
            return 0;
    }

    int ioi_high=-1,ioi_low=1e9;
    for(int i=0;i<m;++i)for(int j=sep[i];j<n;++j)
    {
        ioi_high=max(ioi_high,a[j][i]);
        ioi_low=min(ioi_low,a[j][i]);
        if(ioi_low+x<ioi_high)
            return 0;
    }
    return 1;
}

int ok(int x0)
{
    x = x0;
    return ok_(a, ii, jj) || ok_(b, n-1-ii, jj) || ok_(c, ii, m-1-jj) || ok_(d, n-1-ii, m-1-jj);
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<n;++i)for(int j=0;j<m;++j)
    {
        scanf("%d",a[i]+j), b[n-1-i][j]=a[i][j], c[i][m-1-j]=a[i][j], d[n-1-i][m-1-j]=a[i][j];
        if(a[i][j]>a[ii][jj])ii=i,jj=j;
    }

    int lb=-1,ub=1e9;
    while(ub-lb>1)
    {
        int mid=lb+(ub-lb)/2;
        if(ok(mid))ub=mid;
        else lb=mid;
    }
    printf("%d",ub);
}

Compilation message

joioi.c: In function 'main':
joioi.c:52:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |     scanf("%d%d",&n,&m);
      |     ^~~~~~~~~~~~~~~~~~~
joioi.c:55:9: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         scanf("%d",a[i]+j), b[n-1-i][j]=a[i][j], c[i][m-1-j]=a[i][j], d[n-1-i][m-1-j]=a[i][j];
      |         ^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8696 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8584 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8788 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8696 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8584 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8788 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 6 ms 17500 KB Output is correct
17 Correct 9 ms 17500 KB Output is correct
18 Correct 9 ms 17500 KB Output is correct
19 Correct 8 ms 17500 KB Output is correct
20 Correct 8 ms 17500 KB Output is correct
21 Correct 10 ms 17500 KB Output is correct
22 Correct 10 ms 17500 KB Output is correct
23 Correct 11 ms 17500 KB Output is correct
24 Correct 10 ms 17496 KB Output is correct
25 Correct 10 ms 17376 KB Output is correct
26 Correct 10 ms 17500 KB Output is correct
27 Correct 10 ms 17500 KB Output is correct
28 Correct 10 ms 17500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8696 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8584 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8788 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 2 ms 10584 KB Output is correct
16 Correct 6 ms 17500 KB Output is correct
17 Correct 9 ms 17500 KB Output is correct
18 Correct 9 ms 17500 KB Output is correct
19 Correct 8 ms 17500 KB Output is correct
20 Correct 8 ms 17500 KB Output is correct
21 Correct 10 ms 17500 KB Output is correct
22 Correct 10 ms 17500 KB Output is correct
23 Correct 11 ms 17500 KB Output is correct
24 Correct 10 ms 17496 KB Output is correct
25 Correct 10 ms 17376 KB Output is correct
26 Correct 10 ms 17500 KB Output is correct
27 Correct 10 ms 17500 KB Output is correct
28 Correct 10 ms 17500 KB Output is correct
29 Correct 952 ms 78832 KB Output is correct
30 Correct 745 ms 77392 KB Output is correct
31 Correct 928 ms 78676 KB Output is correct
32 Correct 809 ms 78532 KB Output is correct
33 Correct 842 ms 78516 KB Output is correct
34 Correct 824 ms 78696 KB Output is correct
35 Correct 1319 ms 78680 KB Output is correct
36 Correct 1024 ms 77460 KB Output is correct
37 Correct 1138 ms 78932 KB Output is correct