Submission #637348

# Submission time Handle Problem Language Result Execution time Memory
637348 2022-09-01T12:51:35 Z dattranxxx The Kingdom of JOIOI (JOI17_joioi) C++11
0 / 100
4000 ms 340 KB
#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

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 time Memory Grader output
1 Execution timed out 4066 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 4066 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -