Submission #200803

# Submission time Handle Problem Language Result Execution time Memory
200803 2020-02-08T07:54:35 Z balbit The Kingdom of JOIOI (JOI17_joioi) C++14
100 / 100
2384 ms 65252 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for (int i=(n-1); i>=0; --i)
#define REP1(i,n) FOR(i,1,n+1)
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
#define SQ(x) (x)*(x)
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#ifdef BALBIT
#define IOS()
#define bug(...) fprintf(stderr,"#%d (%s) = ",__LINE__,#__VA_ARGS__),_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define bug(...)
#endif

const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"-1\n"; exit(0);}

ll mpow(ll a, ll n, ll mo = mod){ // a^n % mod
    ll re=1;
    while (n>0){
        if (n&1) re = re*a %mo;
        a = a*a %mo;
        n>>=1;
    }
    return re;
}

ll inv (ll b){
    return b==1?1:(mod-mod/b) * inv(mod%b) % mod;
}

const int maxn = 2003;

int g[maxn][maxn], ps[maxn][maxn];
int n, m;
int Max = 0, Min = 1e9+100;
int ans(){
    int l = 0, r = 1e9+1;
    while (l!=r){
        int df = (l+r)/2;
        bool B = 1;
        REP(i,n) REP(j,m) {
            ps[i+1][j+1]=0;
            if (g[i][j]<=Max-df) ps[i+1][j+1]++;
            ps[i+1][j+1] += ps[i][j+1] + ps[i+1][j] - ps[i][j];
            if (g[i][j]>=Min+df && ps[i+1][j+1]>0){
                B = 0; break;
            }
        }
        if (B == 1){
            r = df;
        }else{
            l = df+1;
        }
    }
    return l-1;
}

void f1(){
    REP(j,m){
        REP(i,n/2){
            swap(g[i][j],g[n-i-1][j]);
        }
    }
}
void f2(){
    REP(i,n){
        REP(j,m/2){
            swap(g[i][j],g[i][m-j-1]);
        }
    }
}
void dump(){
#ifdef BALBIT
    REP(i,n) REP(j,m) cout<<g[i][j]<<" \n"[j==m-1];
#endif // BALBIT
}
signed main(){
    IOS();
    cin>>n>>m;
    REP(i,n) REP(j,m) cin>>g[i][j], MX(Max, g[i][j]),MN(Min,g[i][j]);
    ll re = ans();
    bug(re);
    f1();
    MN(re,ans());
    f2();
    MN(re,ans());
    f1();
    MN(re,ans());
    cout<<re<<endl;
    // Check your array bounds!
    // Think about corner cases (smallest or biggest?)
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 23 ms 2168 KB Output is correct
17 Correct 29 ms 2296 KB Output is correct
18 Correct 30 ms 2168 KB Output is correct
19 Correct 29 ms 2168 KB Output is correct
20 Correct 26 ms 2040 KB Output is correct
21 Correct 27 ms 2168 KB Output is correct
22 Correct 28 ms 2268 KB Output is correct
23 Correct 27 ms 2168 KB Output is correct
24 Correct 25 ms 2040 KB Output is correct
25 Correct 30 ms 2168 KB Output is correct
26 Correct 27 ms 2424 KB Output is correct
27 Correct 26 ms 2296 KB Output is correct
28 Correct 27 ms 2168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 6 ms 376 KB Output is correct
16 Correct 23 ms 2168 KB Output is correct
17 Correct 29 ms 2296 KB Output is correct
18 Correct 30 ms 2168 KB Output is correct
19 Correct 29 ms 2168 KB Output is correct
20 Correct 26 ms 2040 KB Output is correct
21 Correct 27 ms 2168 KB Output is correct
22 Correct 28 ms 2268 KB Output is correct
23 Correct 27 ms 2168 KB Output is correct
24 Correct 25 ms 2040 KB Output is correct
25 Correct 30 ms 2168 KB Output is correct
26 Correct 27 ms 2424 KB Output is correct
27 Correct 26 ms 2296 KB Output is correct
28 Correct 27 ms 2168 KB Output is correct
29 Correct 2154 ms 31700 KB Output is correct
30 Correct 2166 ms 53240 KB Output is correct
31 Correct 2384 ms 55032 KB Output is correct
32 Correct 2246 ms 54804 KB Output is correct
33 Correct 1977 ms 47992 KB Output is correct
34 Correct 2293 ms 54916 KB Output is correct
35 Correct 2215 ms 53800 KB Output is correct
36 Correct 2047 ms 65252 KB Output is correct
37 Correct 2342 ms 53728 KB Output is correct