Submission #260372

#TimeUsernameProblemLanguageResultExecution timeMemory
260372AM1648The Kingdom of JOIOI (JOI17_joioi)C++17
0 / 100
0 ms384 KiB
/* be name khoda */ // #define long_enable #include <iostream> #include <algorithm> #include <cstring> #include <numeric> #include <vector> #include <fstream> #include <set> #include <map> using namespace std; #ifdef long_enable typedef long long int ll; #else typedef int ll; #endif typedef pair<ll, ll> pii; typedef pair<pii, ll> ppi; typedef pair<ll, pii> pip; typedef vector<ll> vi; typedef vector<pii> vpii; #define forifrom(i, s, n) for (ll i = s; i < n; ++i) #define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i) #define fori(i, n) forifrom (i, 0, n) #define forir(i, n) forirto (i, n, 0) #define F first #define S second #define pb push_back #define eb emplace_back #define all(x) (x).begin(), (x).end() #define smin(a, b) a = min(a, (b)) #define smax(a, b) a = max(a, (b)) #define debug(x) cout << #x << " -> " << (x) << endl #define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl #define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl #define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl #define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl #define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl const ll MOD = 1000000007; const ll INF = 1000000000; const long long BIG = 1446803456761533460LL; #define XL (x << 1) #define XR (XL | 1) #define MD ((l + r) >> 1) #define Add(a, b) a = ((a) + (b)) % MOD #define Mul(a, b) a = (1LL * (a) * (b)) % MOD // ----------------------------------------------------------------------- const ll maxn = 2010; typedef array<array<ll, maxn>, maxn> Grid; ll n, m; Grid A, B; bool check(Grid &A, ll k) { ll h = 0; forir (i, n) { fori (j, h) { if (abs(A[i][j] - A[i + 1][j]) > k) return false; } ll j = m; while (j > h && abs(A[i][j] - A[i][j - 1]) <= k && abs(A[i + 1][j - 1] - A[i][j - 1]) <= k) --j; h = j; fori (j, h - 1) { if (abs(A[i][j] - A[i][j + 1]) > k) return false; } } return true; } int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); cin >> n >> m; fori (i, n) fori (j, m) cin >> A[i][j], B[i][m - 1 - j] = A[i][j]; fori (i, n) A[i][m] = A[i][m - 1], B[i][m] = B[i][m - 1]; fori (j, m) A[n][j] = A[n - 1][j], B[n][j] = B[n - 1][j]; ll l = -1, r = INF; while (r - l > 1) { ll mid = (l + r) / 2; if (check(A, mid) || check(B, mid)) r = mid; else l = mid; } cout << r << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...