Submission #416257

# Submission time Handle Problem Language Result Execution time Memory
416257 2021-06-02T08:54:32 Z Vladth11 The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2713 ms 117544 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "
//#include"holiday.h"

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;
typedef tree <ll, null_type, less_equal <ll>, rb_tree_tag, tree_order_statistics_node_update> OST;

const ll NMAX = 2001;
const ll INF = (1LL << 60);
const ll HALF = (1LL << 59);
const ll MOD = 666013;
const ll BLOCK = 225;
const ll base = 31;
const ll nr_of_bits = 21;

int dp[NMAX][NMAX][2];
int sus[NMAX][NMAX];
int jos[NMAX][NMAX];
int mat[NMAX][NMAX];
int joi[NMAX]; /// asta e ala cu minimul
int ioi[NMAX]; /// asta e ala cu maximul
int fjoi[NMAX]; /// asta e ala cu minimul
int fioi[NMAX]; /// asta e ala cu maximul
int maxim = 0;
int minim = 2e9;
int n, m;

bool sePoate(){
     for(int i = 1; i <= n; i++){
        for(int j = 0; j <= m; j++){
            dp[i][j][0] = dp[i][j][1] = 0;
            jos[i][j] = sus[i][j] = 0;
        }
    }
    for(int i = 0; i <= m; i++)
        jos[0][i] = sus[0][i] = 1;
    int ok = 1;
    for(int i = 1; i <= n; i++){
        for(int j = joi[i]; j < fioi[i]; j++){
            dp[i][j][0] |= jos[i - 1][j];
            dp[i][j][1] |= sus[i - 1][j];
        }
        jos[i][0] = dp[i][0][0];
        for(int j = 1; j <= m; j++){
            jos[i][j] = (jos[i][j - 1] | dp[i][j][0]);
        }
        sus[i][m] = dp[i][m][1];
        for(int j = m - 1; j >= 0; j--){
            sus[i][j] = (sus[i][j + 1] | dp[i][j][1]);
        }
    }
    return (jos[n][m] | sus[n][0]);
}

bool OK(int dif){
    if(maxim - minim <= dif)
        return 1;
    for(int j = 1; j <= n; j++){
        ioi[j] = joi[j] = 0;
        fioi[j] = fjoi[j] = m + 1;
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            if(minim + dif < mat[i][j] && maxim - dif > mat[i][j])
                return 0;
            if(minim + dif >= mat[i][j] && maxim - dif > mat[i][j]){
                joi[i] = j;
                if(fjoi[i] == m + 1)
                    fjoi[i] = j;
            }
            else if(minim + dif < mat[i][j] && maxim - dif <= mat[i][j]){
                ioi[i] = j;
                if(fioi[i] == m + 1)
                    fioi[i] = j;
            }
        }
    }
    int ok = sePoate();
    for(int i = 1; i <= n; i++){
        swap(ioi[i], joi[i]);
        swap(fioi[i], fjoi[i]);
    }
    ok |= sePoate();
    return ok;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int i, j;
    cin >> n >> m;
    for(i = 1; i <= n; i++){
        for(j = 1; j <= m; j++){
            cin >> mat[i][j];
            maxim = max(maxim, mat[i][j]);
            minim = min(minim, mat[i][j]);
        }
    }
    int r = 0, pas = (1 << 30);
   while(pas){
        if(!OK(r + pas))
            r += pas;
        pas /= 2;
    }
    if(!OK(r))
        r++;
    cout << r;
    return 0;
}

Compilation message

joioi.cpp: In function 'bool sePoate()':
joioi.cpp:44:9: warning: unused variable 'ok' [-Wunused-variable]
   44 |     int ok = 1;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 6 ms 4300 KB Output is correct
17 Correct 13 ms 4560 KB Output is correct
18 Correct 11 ms 4516 KB Output is correct
19 Correct 17 ms 4488 KB Output is correct
20 Correct 18 ms 4044 KB Output is correct
21 Correct 19 ms 4632 KB Output is correct
22 Correct 12 ms 4684 KB Output is correct
23 Correct 22 ms 4684 KB Output is correct
24 Correct 12 ms 4232 KB Output is correct
25 Correct 24 ms 4684 KB Output is correct
26 Correct 20 ms 4684 KB Output is correct
27 Correct 21 ms 4684 KB Output is correct
28 Correct 22 ms 4732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 456 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 460 KB Output is correct
6 Correct 1 ms 444 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 456 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 452 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 456 KB Output is correct
15 Correct 1 ms 588 KB Output is correct
16 Correct 6 ms 4300 KB Output is correct
17 Correct 13 ms 4560 KB Output is correct
18 Correct 11 ms 4516 KB Output is correct
19 Correct 17 ms 4488 KB Output is correct
20 Correct 18 ms 4044 KB Output is correct
21 Correct 19 ms 4632 KB Output is correct
22 Correct 12 ms 4684 KB Output is correct
23 Correct 22 ms 4684 KB Output is correct
24 Correct 12 ms 4232 KB Output is correct
25 Correct 24 ms 4684 KB Output is correct
26 Correct 20 ms 4684 KB Output is correct
27 Correct 21 ms 4684 KB Output is correct
28 Correct 22 ms 4732 KB Output is correct
29 Correct 1461 ms 96864 KB Output is correct
30 Correct 1554 ms 100200 KB Output is correct
31 Correct 1627 ms 101760 KB Output is correct
32 Correct 1124 ms 101776 KB Output is correct
33 Correct 826 ms 89152 KB Output is correct
34 Correct 1563 ms 101884 KB Output is correct
35 Correct 2221 ms 117412 KB Output is correct
36 Correct 1449 ms 111920 KB Output is correct
37 Correct 2713 ms 117544 KB Output is correct