Submission #637348

#TimeUsernameProblemLanguageResultExecution timeMemory
637348dattranxxxThe Kingdom of JOIOI (JOI17_joioi)C++11
0 / 100
4066 ms340 KiB
#include<bits/stdc++.h> using namespace std; using ll = long long; const int N = 2000 + 5, inf = 1e9; int a[N][N]; int n, m, max_val = -inf, min_val = inf; void flipRow() { for (int i = 0; i < n/2; ++i) swap(a[i], a[n-i-1]); } void flipCol() { for (int j = 0; j < m/2; ++j) for (int i = 0; i < n; ++i) swap(a[i][j], a[i][m-j-1]); } int botLeft(int mid) { for (int i = 0, cur_r = -1; i < n; ++i) { while (cur_r + 1 < m && max_val - a[i][cur_r+1] <= mid) cur_r++; for (int j = cur_r + 1; j < m; ++j) if (a[i][j] - min_val > mid) return 0; } } int check(int mid) { int flag = 0; for (int msk = 0; msk < 4; ++msk) { if (msk & 1) flipRow(); if (msk & 3) flipCol(); flag |= botLeft(mid); if (msk & 1) flipRow(); if (msk & 3) flipCol(); } return flag; } int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); cin >> n >> m; for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> a[i][j], max_val = max(max_val, a[i][j]), min_val = min(min_val, a[i][j]); int lo = 0, hi = 1e9, mid, ans; while (lo <= hi) { mid = lo + hi >> 1; if (check(mid)) ans = mid, hi = mid - 1; else lo = mid + 1; } cout << ans; return 0; }

Compilation message (stderr)

joioi.cpp: In function 'int main()':
joioi.cpp:44:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |     mid = lo + hi >> 1;
      |           ~~~^~~~
joioi.cpp: In function 'int botLeft(int)':
joioi.cpp:20:1: warning: control reaches end of non-void function [-Wreturn-type]
   20 | }
      | ^
joioi.cpp: In function 'int main()':
joioi.cpp:50:11: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |   cout << ans;
      |           ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...