Submission #376546

#TimeUsernameProblemLanguageResultExecution timeMemory
376546smjleoThe Kingdom of JOIOI (JOI17_joioi)C++14
100 / 100
1415 ms42092 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; #define int long long #define nl '\n' #define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0) const int mod = 1000000007, mod2 = 998244353; // change this const int N = 2005; int n, m, arr[N][N], k, mini = INT_MAX, maxi = INT_MIN; bool can() { int last = 0; for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { if (arr[i][j] < maxi-k) last = max(last, j+1); } for (int j=0; j<m; j++) { if (arr[i][j] > mini+k && j < last) return false; } } return true; } void flipx() { for (int i=0; i<n; i++) for (int j=0; j<m/2; j++) swap(arr[i][j], arr[i][m-j-1]); } void flipy() { for (int i=0; i<n/2; i++) { for (int j=0; j<m; j++) swap(arr[i][j], arr[n-i-1][j]); } } int verify(int kk) { k = kk; bool res = false; for (bool _ : {0, 0}) { res |= can(); flipx(); res |= can(); flipy(); } return res; } signed main() { io; cin >> n >> m; for (int i=0; i<n; i++) { for (int j=0; j<m; j++) { cin >> arr[i][j]; mini = min(mini, arr[i][j]); maxi = max(maxi, arr[i][j]); } } int l = 0, r = 1e9+5; while (l<r) { int mid = (l+r)/2; if (verify(mid)) r = mid; else l = mid+1; } cout << l << nl; }

Compilation message (stderr)

joioi.cpp: In function 'long long int verify(long long int)':
joioi.cpp:45:15: warning: unused variable '_' [-Wunused-variable]
   45 |     for (bool _ : {0, 0}) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...