#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(); dump();
MN(re,ans());
f2(); dump();
MN(re,ans());
f1(); dump();
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 |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
372 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 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 |
392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
372 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 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 |
392 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
25 ms |
2296 KB |
Output is correct |
17 |
Correct |
29 ms |
2552 KB |
Output is correct |
18 |
Correct |
28 ms |
2552 KB |
Output is correct |
19 |
Correct |
29 ms |
2680 KB |
Output is correct |
20 |
Correct |
28 ms |
2296 KB |
Output is correct |
21 |
Correct |
27 ms |
2552 KB |
Output is correct |
22 |
Correct |
28 ms |
2552 KB |
Output is correct |
23 |
Correct |
29 ms |
2552 KB |
Output is correct |
24 |
Correct |
25 ms |
2296 KB |
Output is correct |
25 |
Correct |
29 ms |
2584 KB |
Output is correct |
26 |
Correct |
27 ms |
2552 KB |
Output is correct |
27 |
Correct |
27 ms |
2680 KB |
Output is correct |
28 |
Correct |
27 ms |
2552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
380 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
504 KB |
Output is correct |
4 |
Correct |
5 ms |
380 KB |
Output is correct |
5 |
Correct |
5 ms |
504 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
372 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 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 |
392 KB |
Output is correct |
15 |
Correct |
6 ms |
376 KB |
Output is correct |
16 |
Correct |
25 ms |
2296 KB |
Output is correct |
17 |
Correct |
29 ms |
2552 KB |
Output is correct |
18 |
Correct |
28 ms |
2552 KB |
Output is correct |
19 |
Correct |
29 ms |
2680 KB |
Output is correct |
20 |
Correct |
28 ms |
2296 KB |
Output is correct |
21 |
Correct |
27 ms |
2552 KB |
Output is correct |
22 |
Correct |
28 ms |
2552 KB |
Output is correct |
23 |
Correct |
29 ms |
2552 KB |
Output is correct |
24 |
Correct |
25 ms |
2296 KB |
Output is correct |
25 |
Correct |
29 ms |
2584 KB |
Output is correct |
26 |
Correct |
27 ms |
2552 KB |
Output is correct |
27 |
Correct |
27 ms |
2680 KB |
Output is correct |
28 |
Correct |
27 ms |
2552 KB |
Output is correct |
29 |
Execution timed out |
414 ms |
34660 KB |
Time limit exceeded (wall clock) |
30 |
Halted |
0 ms |
0 KB |
- |