Submission #124782

# Submission time Handle Problem Language Result Execution time Memory
124782 2019-07-04T01:44:00 Z ainta The Kingdom of JOIOI (JOI17_joioi) C++17
0 / 100
2 ms 256 KB
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
int n, m;
int w[2010][2010], Mn = 2e9;
bool Pos(int K){
    int i, j, M1 = 2e9, M2 = 0;
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            if(w[i][j] > Mn+K)break;
        }
        for(;j<=m;j++){
            M1 = min(M1, w[i][j]);
            M2 = max(M2, w[i][j]);
        }
        if(M2-M1>K)break;
    }
    if(M2-M1<=K)return true;
    M1=2e9,M2=0;
    for(i=1;i<=n;i++){
        for(j=m;j>=1;j--){
            if(w[i][j] > Mn+K)break;
        }
        for(;j>=1;j--){
            M1 = min(M1, w[i][j]);
            M2 = max(M2, w[i][j]);
        }
        if(M2-M1>K)break;
    }
    if(M2-M1<=K)return true;
    return false;
}
int main() {
    int i, j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++){
        for(j=1;j<=m;j++){
            scanf("%d",&w[i][j]);
            Mn = min(Mn, w[i][j]);
        }
    }
    int b = 0, e = 1e9, mid, r;
    while(b<=e){
        mid=(b+e)>>1;
        if(Pos(mid))r=mid, e=mid-1;
        else b=mid+1;
    }
    printf("%d\n",r);
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:36:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
joioi.cpp:39:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&w[i][j]);
             ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -