답안 #153246

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
153246 2019-09-13T03:24:05 Z arnold518 The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
2 ms 380 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;
        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;
        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]);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 380 KB Output isn't correct
3 Halted 0 ms 0 KB -