Submission #143405

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
1434052019-08-13 23:56:10osaaateiasavtnlThe Kingdom of JOIOI (JOI17_joioi)C++14
100 / 100
2584 ms133528 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
const int N = 2007, INF = 1e9 + 7;
int n, m, mn = INF, a[N][N], r[N];
int suffmn[N][N], suffmx[N][N];
bool check_(int mid) {
for (int i = 0; i < n; ++i) {
suffmn[i][m] = INF; for (int j = m - 1; j >= 0; --j) suffmn[i][j] = min(suffmn[i][j + 1], a[i][j]);
suffmx[i][m] = -INF; for (int j = m - 1; j >= 0; --j) suffmx[i][j] = max(suffmx[i][j + 1], a[i][j]);
}
int mx = mn + mid;
for (int i = 0; i < n; ++i) { r[i] = 0; while (r[i] < m && a[i][r[i]] <= mx) ++r[i]; }
int MN, MX, c;
c = m; MN = INF; MX = -INF;
for (int i = 0; i < n; ++i) { c = min(c, r[i]); MN = min(MN, suffmn[i][c]); MX = max(MX, suffmx[i][c]); }
if (MX - MN <= mid) return 1;
c = m; MN = INF; MX = -INF;
for (int i = n - 1; i >= 0; --i) { c = min(c, r[i]); MN = min(MN, suffmn[i][c]); MX = max(MX, suffmx[i][c]); }
if (MX - MN <= mid) return 1;
return 0;
}
void kek() {
for (int i = 0; i < n; ++i) for (int j = 0; j < m / 2; ++j) swap(a[i][j], a[i][m - 1 - j]);
}
bool check(int mid) {
if (check_(mid)) return 1;
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...