Submission #403645

# Submission time Handle Problem Language Result Execution time Memory
403645 2021-05-13T10:39:27 Z cpp219 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
1819 ms 102336 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 "test"
    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(); 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);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 9 ms 2636 KB Output is correct
17 Correct 18 ms 2920 KB Output is correct
18 Correct 13 ms 2876 KB Output is correct
19 Correct 14 ms 2892 KB Output is correct
20 Correct 13 ms 2508 KB Output is correct
21 Correct 17 ms 3020 KB Output is correct
22 Correct 15 ms 3016 KB Output is correct
23 Correct 18 ms 3020 KB Output is correct
24 Correct 14 ms 2720 KB Output is correct
25 Correct 21 ms 3044 KB Output is correct
26 Correct 17 ms 3020 KB Output is correct
27 Correct 18 ms 3044 KB Output is correct
28 Correct 17 ms 3020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 360 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 9 ms 2636 KB Output is correct
17 Correct 18 ms 2920 KB Output is correct
18 Correct 13 ms 2876 KB Output is correct
19 Correct 14 ms 2892 KB Output is correct
20 Correct 13 ms 2508 KB Output is correct
21 Correct 17 ms 3020 KB Output is correct
22 Correct 15 ms 3016 KB Output is correct
23 Correct 18 ms 3020 KB Output is correct
24 Correct 14 ms 2720 KB Output is correct
25 Correct 21 ms 3044 KB Output is correct
26 Correct 17 ms 3020 KB Output is correct
27 Correct 18 ms 3044 KB Output is correct
28 Correct 17 ms 3020 KB Output is correct
29 Correct 1101 ms 82576 KB Output is correct
30 Correct 1127 ms 85096 KB Output is correct
31 Correct 1315 ms 86632 KB Output is correct
32 Correct 1082 ms 86688 KB Output is correct
33 Correct 920 ms 75736 KB Output is correct
34 Correct 1180 ms 86800 KB Output is correct
35 Correct 1533 ms 102200 KB Output is correct
36 Correct 1267 ms 96844 KB Output is correct
37 Correct 1819 ms 102336 KB Output is correct