Submission #321651

# Submission time Handle Problem Language Result Execution time Memory
321651 2020-11-13T01:24:42 Z daniel920712 The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 364 KB
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;
int all[2005][2005];
int l1[2005],r1[2005];
int l2[2005],r2[2005];
map < int , vector < pair < int , int > > > where;

int main()
{
    int small=2e9,big=0,l,r,N,M,ok,x,y,a,b,c,d,i,j,k;
    scanf("%d %d",&N,&M);
    for(i=0;i<N;i++)
    {
        for(j=0;j<M;j++)
        {
            scanf("%d",&all[i][j]);
            where[all[i][j]].push_back(make_pair(i,j));
            small=min(small,all[i][j]);
            big=max(big,all[i][j]);
        }
    }
    l=0;
    r=(big-small+1);
    while((r-l)>1)
    {
        ok=1;
        for(auto i:where)
        {
            if(i.first>small+(r+l)/2) if(big-i.first>(r+l)/2) ok=0;
            if(i.first<big-(r+l)/2) if(i.first-small>(r+l)/2) ok=0;
        }
        if(ok==0)
        {
            l=(r+l)/2;
            continue;
        }
        for(i=0;i<N;i++)
        {
            l1[i]=l2[i]=N;
            r1[i]=r2[i]=-1;
        }
        for(auto i:where)
        {
            for(auto j:i.second)
            {
                if(i.first>small+(r+l)/2)
                {
                    l1[j.first]=min(l1[j.first],j.second);
                    r1[j.first]=max(r1[j.first],j.second);
                }
                if(i.first<big-(r+l)/2)
                {
                    l2[j.first]=min(l2[j.first],j.second);
                    r2[j.first]=max(r2[j.first],j.second);
                }
            }

        }
        /*printf("aa %d\n",(l+r)/2);
        for(i=0;i<N;i++) printf("%d %d\n",r1[i],l2[i]);
        printf("\n");
        for(i=0;i<N;i++) printf("%d %d\n",r2[i],l1[i]);
        printf("\n");*/


        a=b=c=d=1;

        x=N;
        for(i=0;i<N;i++)
        {
            x=min(x,l1[i]);
            if(x<=r2[i]) a=0;
        }

        x=0;
        for(i=0;i<N;i++)
        {
            x=max(x,r2[i]);
            if(x>=l1[i]) b=0;
        }

        x=N;
        for(i=0;i<N;i++)
        {
            x=min(x,l2[i]);
            if(x<=r1[i]) c=0;
        }

        x=0;
        for(i=0;i<N;i++)
        {
            x=max(x,r1[i]);
            if(x>=l2[i]) d=0;
        }

        if(a||b||c||d) r=(l+r)/2;
        else l=(r+l)/2;



    }
    ok=1;
    for(auto i:where)
    {
        if(i.first>small+l) if(big-i.first>l) ok=0;
        if(i.first<big-l) if(i.first-small>l) ok=0;
    }
    if(ok==0)
    {
        printf("%d\n",r);
        return 0;
    }
    for(i=0;i<N;i++)
    {
        l1[i]=l2[i]=N;
        r1[i]=r2[i]=-1;
    }
    for(auto i:where)
    {
        for(auto j:i.second)
        {
            if(i.first>small+l)
            {
                l1[j.first]=min(l1[j.first],j.second);
                r1[j.first]=max(r1[j.first],j.second);
            }
            if(i.first<big-l)
            {
                l2[j.first]=min(l2[j.first],j.second);
                r2[j.first]=max(r2[j.first],j.second);
            }
        }

    }


    a=b=c=d=1;

    x=N;
    for(i=0;i<N;i++)
    {
        x=min(x,l1[i]);
        if(x<=r2[i]) a=0;
    }

    x=0;
    for(i=0;i<N;i++)
    {
        x=max(x,r2[i]);
        if(x>=l1[i]) b=0;
    }

    x=N;
    for(i=0;i<N;i++)
    {
        x=min(x,l2[i]);
        if(x<=r1[i]) c=0;
    }

    x=0;
    for(i=0;i<N;i++)
    {
        x=max(x,r1[i]);
        if(x>=l2[i]) d=0;
    }

    if(a||b||c||d) printf("%d\n",l);
    else printf("%d\n",r);



    return 0;
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:17:38: warning: unused variable 'y' [-Wunused-variable]
   17 |     int small=2e9,big=0,l,r,N,M,ok,x,y,a,b,c,d,i,j,k;
      |                                      ^
joioi.cpp:17:52: warning: unused variable 'k' [-Wunused-variable]
   17 |     int small=2e9,big=0,l,r,N,M,ok,x,y,a,b,c,d,i,j,k;
      |                                                    ^
joioi.cpp:18:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d %d",&N,&M);
      |     ~~~~~^~~~~~~~~~~~~~~
joioi.cpp:23:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   23 |             scanf("%d",&all[i][j]);
      |             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -