# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124556 | wilwxk | The Kingdom of JOIOI (JOI17_joioi) | C++14 | 928 ms | 70628 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN=2e3+5;
int v[3][MAXN][MAXN];
int n, m, maior, menor;
bool testa(int val, int k) {
vector<pair<int, int> > inter;
for(int i=1; i<=n; i++) {
int a=m+1, b=0;
while(a-1>=1&&v[k][i][a-1]>=maior-val) a--;
while(b+1<=m&&v[k][i][b+1]<=menor+val) b++;
a--; if(a>b) return 0;
inter.push_back({a, b});
}
bool ok=1, ok2=1;
int ult=0, ult2=m+1;
for(auto cur : inter) {
if(cur.second<ult) ok=0;
if(cur.first>ult2) ok2=0;
ult=max(ult, cur.first);
ult2=min(ult2, cur.second);
}
return (ok||ok2);
}
bool testa2(int k) {
return (testa(k, 1)||testa(k, 2));
}
int main() {
scanf("%d %d", &n, &m);
maior=-1; menor=1e9+9;
for(int i=1; i<=n; i++) {
for(int j=1; j<=m; j++) {
scanf("%d", &v[1][i][j]);
v[2][i][m-j+1]=v[1][i][j];
maior=max(maior, v[1][i][j]);
menor=min(menor, v[1][i][j]);
}
}
int respf=0;
// testa(11, 1);
for(int i=maior; i>0; i/=2) while(respf+i<=maior&&!testa2(respf+i)) respf+=i;
printf("%d\n", respf+1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |