Submission #480717

#TimeUsernameProblemLanguageResultExecution timeMemory
480717Mackerel_PikeThe Kingdom of JOIOI (JOI17_joioi)C++14
100 / 100
628 ms54936 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2005; int n, m, mn, mx; int a[maxn][maxn]; int l[maxn], r[maxn]; inline bool solve(int md){ for(int i = 0; i < n; ++i){ for(r[i] = -1; r[i] + 1 < m && a[i][r[i] + 1] >= mx - md; ++r[i]); for(l[i] = m; l[i] - 1 >= 0 && a[i][l[i] - 1] <= mn + md; --l[i]); --l[i]; if(l[i] > r[i]) return false; } int lst = -1; bool ok = true; for(int i = 0; i < n; ++i){ lst = max(lst, l[i]); ok &= (lst <= r[i]); } if(ok) return true; lst = m; for(int i = 0; i < n; ++i){ lst = min(lst, r[i]); if(lst < l[i]) return false; } return true; } inline bool check(int md){ if(solve(md)) return true; for(int i = 0; i < n; ++i) reverse(a[i], a[i] + m); return solve(md); } int main(){ //freopen("joioi.in", "r", stdin); scanf("%d%d", &n, &m); mx = 0, mn = 0x3f3f3f3f; for(int i = 0; i < n; ++i) for(int j = 0; j < m; ++j) scanf("%d", &a[i][j]), mx = max(mx, a[i][j]), mn = min(mn, a[i][j]); int lb = -1, rb = 1e9; for(; lb + 1 < rb; ){ int md = lb + rb >> 1; if(check(md)) rb = md; else lb = md; } printf("%d\n", rb); return 0; }

Compilation message (stderr)

joioi.cpp: In function 'int main()':
joioi.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |     int md = lb + rb >> 1;
      |              ~~~^~~~
joioi.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |   scanf("%d%d", &n, &m);
      |   ~~~~~^~~~~~~~~~~~~~~~
joioi.cpp:51:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |       scanf("%d", &a[i][j]), mx = max(mx, a[i][j]), mn = min(mn, a[i][j]);
      |       ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...