Submission #561210

#TimeUsernameProblemLanguageResultExecution timeMemory
561210flappybirdThe Kingdom of JOIOI (JOI17_joioi)C++17
100 / 100
746 ms55620 KiB
#include <bits/stdc++.h> #include <cassert> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 2100 #define MAXS 20 #define INF 1000000000000000001 #define bb ' ' #define ln '\n' #define Ln '\n' int arr[MAX][MAX]; pii range[MAX]; int N, M; bool rchk() { int i; int mnn = -1; bool cc = true; for (i = 1; i <= N; i++) { if (mnn < range[i].first) mnn = range[i].first; else { if (mnn >= range[i].second) { cc = false; break; } } } if (cc) return true; cc = true; mnn = -1; for (i = N; i >= 1; i--) { if (mnn < range[i].first) mnn = range[i].first; else { if (mnn >= range[i].second) { cc = false; break; } } } return cc; } signed main() { ios::sync_with_stdio(false), cin.tie(0); cin >> N >> M; int i, j; int mn = 1000000010; int mx = 0; for (i = 1; i <= N; i++) { for (j = 1; j <= M; j++) { cin >> arr[i][j]; mx = max(arr[i][j], mx); mn = min(arr[i][j], mn); } } if (mx == mn) { cout << 0 << ln; return 0; } int l, r; l = -1; r = mx - mn; int mid; while (r - l > 1) { mid = (l + r + 1) / 2; bool chk = true; for (i = 1; i <= N; i++) { range[i] = { 0, M + 1 }; for (j = 1; j <= M; j++) if (mx - arr[i][j] > mid) range[i].first = j; for (j = M; j >= 1; j--) if (arr[i][j] - mn > mid) range[i].second = j; if (range[i].first >= range[i].second) { chk = false; break; } } if (chk) chk = rchk(); if (!chk) { chk = true; for (i = 1; i <= N; i++) { range[i] = { 0, M + 1 }; for (j = 1; j <= M; j++) if (arr[i][j] - mn > mid) range[i].first = j; for (j = M; j >= 1; j--) if (mx - arr[i][j] > mid) range[i].second = j; if (range[i].first >= range[i].second) { chk = false; break; } } if (chk) chk = rchk(); } if (chk) r = mid; else l = mid; } cout << r << ln; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...