Submission #153248

# Submission time Handle Problem Language Result Execution time Memory
153248 2019-09-13T03:29:23 Z arnold518 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
948 ms 54880 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2000;

int H, W, A[MAXN+10][MAXN+10];
int minval=2e9, maxval=-1;

bool decide(int x)
{
    int i, j, t;
    int p=minval+x+1, q=maxval-x-1;
    bool flag;
    vector<pii> V;

    flag=true; V.clear();
    for(i=1; i<=H; i++)
    {
        int s=0, e=W+1;
        for(j=1; j<=W; j++) if(minval<=A[i][j] && A[i][j]<=q) s=j;
        for(j=W; j>=1; j--) if(p<=A[i][j] && A[i][j]<=maxval) e=j;
        if(e<=s) { flag=false; break; }
        V.push_back({s, e-1});
    }
    if(flag)
    {
        t=0; flag=true;
        for(i=0; i<H; i++)
        {
            if(t<V[i].first) t=V[i].first;
            else if(t>V[i].second) { flag=false; break; }
        }
        if(flag) return true;

        t=0; flag=true;
        for(i=H-1; i>=0; i--)
        {
            if(t<V[i].first) t=V[i].first;
            else if(t>V[i].second) { flag=false; break; }
        }
        if(flag) return true;
    }

    flag=true; V.clear();
    for(i=1; i<=H; i++)
    {
        int s=0, e=W+1;
        for(j=1; j<=W; j++) if(p<=A[i][j] && A[i][j]<=maxval) s=j;
        for(j=W; j>=1; j--) if(minval<=A[i][j] && A[i][j]<=q) e=j;
        if(e<=s) { flag=false; break; }
        V.push_back({s, e-1});
    }
    if(flag)
    {
        t=0; flag=true;
        for(i=0; i<H; i++)
        {
            if(t<V[i].first) t=V[i].first;
            else if(t>V[i].second) { flag=false; break; }
        }
        if(flag) return true;

        t=0; flag=true;
        for(i=H-1; i>=0; i--)
        {
            if(t<V[i].first) t=V[i].first;
            else if(t>V[i].second) { flag=false; break; }
        }
        if(flag) return true;
    }
    return false;
}

int main()
{
    int i, j;

    scanf("%d%d", &H, &W);
    for(i=1; i<=H; i++) for(j=1; j<=W; j++)
    {
        scanf("%d", &A[i][j]);
        minval=min(minval, A[i][j]);
        maxval=max(maxval, A[i][j]);
    }

    int lo=-1, hi=1e9;
    while(lo+1<hi)
    {
        int mid=lo+hi>>1;
        if(decide(mid)) hi=mid;
        else lo=mid;
    }
    printf("%d", hi);
}

Compilation message

joioi.cpp: In function 'int main()':
joioi.cpp:93:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid=lo+hi>>1;
                 ~~^~~
joioi.cpp:82:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &H, &W);
     ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:85:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i][j]);
         ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 11 ms 1528 KB Output is correct
18 Correct 10 ms 1532 KB Output is correct
19 Correct 11 ms 1528 KB Output is correct
20 Correct 10 ms 1400 KB Output is correct
21 Correct 13 ms 1656 KB Output is correct
22 Correct 11 ms 1656 KB Output is correct
23 Correct 13 ms 1656 KB Output is correct
24 Correct 10 ms 1528 KB Output is correct
25 Correct 13 ms 1700 KB Output is correct
26 Correct 12 ms 1656 KB Output is correct
27 Correct 12 ms 1688 KB Output is correct
28 Correct 13 ms 1656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 380 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 9 ms 1400 KB Output is correct
17 Correct 11 ms 1528 KB Output is correct
18 Correct 10 ms 1532 KB Output is correct
19 Correct 11 ms 1528 KB Output is correct
20 Correct 10 ms 1400 KB Output is correct
21 Correct 13 ms 1656 KB Output is correct
22 Correct 11 ms 1656 KB Output is correct
23 Correct 13 ms 1656 KB Output is correct
24 Correct 10 ms 1528 KB Output is correct
25 Correct 13 ms 1700 KB Output is correct
26 Correct 12 ms 1656 KB Output is correct
27 Correct 12 ms 1688 KB Output is correct
28 Correct 13 ms 1656 KB Output is correct
29 Correct 655 ms 37396 KB Output is correct
30 Correct 697 ms 37632 KB Output is correct
31 Correct 798 ms 39212 KB Output is correct
32 Correct 715 ms 39288 KB Output is correct
33 Correct 596 ms 34424 KB Output is correct
34 Correct 800 ms 39392 KB Output is correct
35 Correct 857 ms 54776 KB Output is correct
36 Correct 745 ms 49716 KB Output is correct
37 Correct 948 ms 54880 KB Output is correct