답안 #403642

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403642 2021-05-13T10:38:27 Z cpp219 The Kingdom of JOIOI (JOI17_joioi) C++14
0 / 100
1 ms 336 KB
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")

#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 2e3 + 16;
const ll Log2 = 19;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
///Road to EF/M

ll n,m,a[N][N],b[N][N],ans = inf,mx,mn = inf;
ll resis[N],Inclu[N];
void LeftRight(){
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++) b[i][m - j + 1] = a[i][j];
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++) a[i][j] = b[i][j];
}

void Updown(){
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++) b[n - i + 1][j] = a[i][j];
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++) a[i][j] = b[i][j];
}

void out(){
    for (ll i = 1;i <= n;i++){
        for (ll j = 1;j <= m;j++) cout<<a[i][j]<<" ";
        cout<<"\n";
    }
    exit(0);
}

bool chk(ll mid){
    //if (mx - mid > mn + mid) return 0;
    for (ll i = 1;i <= m;i++) resis[i] = 0,Inclu[i] = inf;
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++){
            if (a[i][j] > mn + mid) Inclu[j] = min(Inclu[j],i);
            if (a[i][j] < mx - mid) resis[j] = max(resis[j],i);
        }
    //for (ll i = 1;i <= m;i++) cout<<Inclu[i]<<" "; exit(0);

    ll now = inf;
    for (ll i = 1;i <= m;i++){
        now = min(now,Inclu[i]);
        //cout<<now<<" x "<<resis[i]<<"\n";
        if (resis[i] >= now) return 0;
    }
    return 1;
}

void oper(){
    ll l,mid,h;
    l = 0; h = mx - mn;
    //cout<<chk(429330304); exit(0);
    while(l <= h){
        mid = (l + h)/2;
        if (chk(mid)) h = mid - 1;
        else l = mid + 1;
    }
    ans = min(ans,l);
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define task "tst"
    if (fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        //freopen(task".out", "w", stdout);
    }
    cin>>n>>m;
    for (ll i = 1;i <= n;i++)
        for (ll j = 1;j <= m;j++) cin>>a[i][j],mx = max(mx,a[i][j]),mn = min(mn,a[i][j]);
    oper(); //cout<<ans; return 0;
    LeftRight(); oper();
    Updown(); oper();
    LeftRight(); out(); oper();
    cout<<ans;
}

Compilation message

joioi.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    1 | #pragma GCC optimization "O2"
      | 
joioi.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    2 | #pragma GCC optimization "unroll-loop"
      | 
joioi.cpp: In function 'int main()':
joioi.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -